Skip to content

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

@aureliar8

Description

@aureliar8

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.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions