Skip to content

CSI driver signal handler goroutine has no cleanup mechanism #283

@poyrazK

Description

@poyrazK

Why is this an issue?

The CSI driver spawns a signal handler goroutine that calls d.Stop() but has no way to synchronize on completion. The goroutine exits after calling Stop with no wait for driver to fully shut down.

What is causing it?

In cmd/csi-driver/main.go:49-54:

c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
go func() {
    <-c
    d.Stop()
}()

When a signal is received:

  1. The goroutine calls d.Stop()
  2. The goroutine exits immediately
  3. There's no synchronization to wait for d.Stop() to complete
  4. The main process may exit before the driver fully stops

How can it be solved?

Add synchronization:

stopped := make(chan struct{})
go func() {
    <-c
    d.Stop()
    close(stopped)
}()

// In Run(), check stopped or use context with timeout
select {
case <-stopped:
    // Driver stopped gracefully
case <-time.After(shutdownTimeout):
    // Force exit
}

Category

  • Medium

Severity

  • Medium

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions