uber-go/fx

1.19 Regression: It's impossible to shutdown from an OS signal after `startCtx` is `Done()`.

aureliar8 opened this issue · 2 comments

Describe the bug
Regression: It's impossible to shutdown from an OS signal after startCtx is Done().

To Reproduce

  1. Start an fx app
  2. Wait startTimeout (default is 15s).
  3. Send SIGTERM to the process
  4. Nothing will handle the signal and the app will not shut down

Expected behavior
The apps shut down correctly like it did in the previous release.

Additional context
This line starts the goroutine that dispatches os signals.

fx/signal.go

Line 118 in 213eb86

go recv.relayer(ctx)

The goroutine then blocks on

fx/signal.go

Lines 82 to 95 in 213eb86

func (recv *signalReceivers) relayer(ctx context.Context) {
defer func() {
recv.finished <- struct{}{}
}()
select {
case <-recv.shutdown:
return
case <-ctx.Done():
return
case signal := <-recv.signals:
recv.Broadcast(ShutdownSignal{
Signal: signal,
})

After the startCtx is Done(), this goroutine exits and thus there's nothing to process OS signals to initiate shutdown.

Replacing the goroutine invocation by go recv.relayer(context.TODO()) fixed the issue for me. The context passed here should not be Done() until the application stops.

tunhvn commented

I have the same issue with Fx v1.19.0, it can't shutdown with Ctrl+C signal (-INT)

Fx v1.18.2 works well.

Thanks for reporting this issue folks and sorry about that regression. Will shortly roll out a patch release that addresses this issue.