diff --git a/CHANGELOG.md b/CHANGELOG.md index 79990345e..d4074f5ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## Unreleased -- No changes yet. +### Deprecated +- Deprecate `ShutdownTimeout` option. ## [1.19.1](https://github.com/uber-go/fx/compare/v1.18.0...v1.19.1) - 2023-01-10 diff --git a/shutdown.go b/shutdown.go index aa81e68d3..eb67caa87 100644 --- a/shutdown.go +++ b/shutdown.go @@ -21,7 +21,6 @@ package fx import ( - "context" "time" ) @@ -57,9 +56,7 @@ func ExitCode(code int) ShutdownOption { type shutdownTimeoutOption time.Duration -func (to shutdownTimeoutOption) apply(s *shutdowner) { - s.shutdownTimeout = time.Duration(to) -} +func (shutdownTimeoutOption) apply(*shutdowner) {} var _ ShutdownOption = shutdownTimeoutOption(0) @@ -67,14 +64,15 @@ var _ ShutdownOption = shutdownTimeoutOption(0) // for a given call to Shutdown method of the [Shutdowner] interface. As the // Shutdown method will block while waiting for a signal receiver relay // goroutine to stop. +// +// Deprecated: This option has no effect. Shutdown is not a blocking operation. func ShutdownTimeout(timeout time.Duration) ShutdownOption { return shutdownTimeoutOption(timeout) } type shutdowner struct { - app *App - exitCode int - shutdownTimeout time.Duration + app *App + exitCode int } // Shutdown broadcasts a signal to all of the application's Done channels @@ -87,19 +85,6 @@ func (s *shutdowner) Shutdown(opts ...ShutdownOption) error { opt.apply(s) } - ctx := context.Background() - - if s.shutdownTimeout != time.Duration(0) { - c, cancel := context.WithTimeout( - context.Background(), - s.shutdownTimeout, - ) - defer cancel() - ctx = c - } - - defer s.app.receivers.Stop(ctx) - return s.app.receivers.Broadcast(ShutdownSignal{ Signal: _sigTERM, ExitCode: s.exitCode, diff --git a/signal.go b/signal.go index 1593c5de2..b804abe7b 100644 --- a/signal.go +++ b/signal.go @@ -139,7 +139,7 @@ func (recv *signalReceivers) Stop(ctx context.Context) error { } } -func (recv *signalReceivers) Done() chan os.Signal { +func (recv *signalReceivers) Done() <-chan os.Signal { recv.m.Lock() defer recv.m.Unlock() @@ -157,7 +157,7 @@ func (recv *signalReceivers) Done() chan os.Signal { return ch } -func (recv *signalReceivers) Wait() chan ShutdownSignal { +func (recv *signalReceivers) Wait() <-chan ShutdownSignal { recv.m.Lock() defer recv.m.Unlock()