uber-go / fx

A dependency injection based application framework for Go.
https://uber-go.github.io/fx/
MIT License
5.72k stars 289 forks source link

signalReceivers should call `Signal.Stop(recv.signals)` when stopped #1197

Closed MarcoPolo closed 4 months ago

MarcoPolo commented 5 months ago

Describe the bug

signalReceivers should call Signal.Stop(recv.signals) when they are Stop()ed.

Because if not, then when a user does:

app.Start(...)
app.Close(...)

// block on anything else
select {} // for example

the program will fail to exit when the user presses ctrl-c. Which is contrary to what one would expect after starting and stopping the fx app.

To Reproduce

Example

func main() {
    app := fx.New()
    app.Start(context.Background())
    app.Stop(context.Background())

    select {}
}

ctrl-c should exit the program

Expected behavior the signal handler reverts back to Go's default signal handler

Additional context should be a ~1 line change :)