Skip to content

fix: graceful shutdown bypasses deferred cleanup due to os.Exit(0) #207

Description

@mayankpande88

Problem

In main.go:173, the signal handler calls os.Exit(0) which bypasses all deferred cleanup functions:

  • registry.Close() — never called
  • tracer.Close() — eBPF programs, uprobes, perf buffers, ring buffers leak
  • profiling.Stop() — never called

On every pod restart/rollout, kernel resources (eBPF maps, programs, uprobes) are leaked. On a daemonset that restarts frequently, this compounds.

Fix

Replace os.Exit(0) with context cancellation. Propagate context.Context through the main function and let deferred cleanup run naturally.

ctx, cancel := context.WithCancel(context.Background())
go func() {
    sigChannel := make(chan os.Signal, 1)
    signal.Notify(sigChannel, os.Interrupt, syscall.SIGTERM)
    <-sigChannel
    klog.Infoln("Received signal, shutting down")
    cancel()
}()
// ... use ctx in main loop ...
// deferred Close() calls will run on natural exit

Impact

High — kernel resource leaks on every restart.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions