Skip to content

Commit

Permalink
feat: Improve server shutdown sequence and add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
mattevans committed Dec 5, 2024
1 parent 7f31c75 commit 8110dbb
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,11 @@ func (x *Xatu) Start(ctx context.Context) error {
}

func (x *Xatu) stop(ctx context.Context) error {
x.log.Info("Beginning server shutdown sequence")
x.log.WithFields(logrus.Fields{
"pre_stop_sleep_seconds": x.config.PreStopSleepSeconds,
}).Info("Beginning server shutdown sequence")

time.Sleep(time.Duration(x.config.PreStopSleepSeconds) * time.Second)

ctx, cancel := context.WithTimeout(ctx, 20*time.Second)
defer cancel()
Expand Down Expand Up @@ -386,6 +390,9 @@ func (x *Xatu) startGrpcServer(ctx context.Context) error {

x.log.WithField("addr", x.config.Addr).Info("Starting gRPC server")

// Upon shutdown, the listener will be closed by (grpcServer).GracefulStop(). This
// will trigger a net.ErrClosed error (normal behavior), and we can return nil.
// Think of net.ErrClosed as 'listener was closed intentionally'.
err = x.grpcServer.Serve(lis)
if err != nil && !errors.Is(err, net.ErrClosed) {
return err
Expand Down

0 comments on commit 8110dbb

Please sign in to comment.