Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
25 changes: 5 additions & 20 deletions shutdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
package fx

import (
"context"
"time"
)

Expand Down Expand Up @@ -57,24 +56,23 @@ 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)

// ShutdownTimeout is a [ShutdownOption] that allows users to specify a timeout
// 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
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions signal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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()

Expand Down