Skip to content

Commit

Permalink
Merge pull request #20 from ne-sachirou/fix-lostcancel
Browse files Browse the repository at this point in the history
Fix lostcancel
  • Loading branch information
ne-sachirou authored Dec 25, 2024
2 parents 742b359 + c5e91f4 commit f1f8ccf
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions graceful.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ func GracefulSignals(signals ...os.Signal) Option {

// GracefulShutdownTimeout sets timeout for shutdown. Default is 0.
func GracefulShutdownTimeout(timeout time.Duration) Option {
return func(o *gracefulOpts) { o.ShutdownTimeout = timeout }
return func(o *gracefulOpts) {
o.ShutdownTimeout = timeout
}
}

// Graceful runs all servers contained in `s`, then waits signals.
Expand All @@ -58,7 +60,7 @@ func (s Servers) Graceful(ctx context.Context, options ...Option) error {
ctx, stop := signal.NotifyContext(ctx, opts.Signals...)
defer stop()

ctx, cancel := context.WithCancelCause(ctx)
ctx, cancel := context.WithCancelCause(ctx) // nolint:govet

for _, srv := range s.Servers {
go func(ctx context.Context, srv Server) {
Expand All @@ -72,7 +74,7 @@ func (s Servers) Graceful(ctx context.Context, options ...Option) error {

<-ctx.Done()
if err := context.Cause(ctx); err != nil && !errors.Is(err, context.Canceled) {
return errors.Join(errors.New("failed to start servers"), err)
return errors.Join(errors.New("failed to start servers"), err) // nolint:govet
}

ctx, cancelT := context.WithTimeout(context.Background(), opts.ShutdownTimeout)
Expand Down

0 comments on commit f1f8ccf

Please sign in to comment.