Skip to content

Commit

Permalink
Rename variable and comment to match the behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
mostafa committed Dec 26, 2024
1 parent 3222ffd commit 5d9801f
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions cmd/gatewayd_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -1084,13 +1084,14 @@ func (app *GatewayDApp) stopGracefully(runCtx context.Context, sig os.Signal) {
span.AddEvent("Stopped metrics server")
}
}
earlyExit := false

properlyInitialized := false
for name, server := range app.servers {
if server.IsRunning() {
logger.Info().Str("name", name).Msg("Stopping server")
server.Shutdown()
span.AddEvent("Stopped server")
earlyExit = true
properlyInitialized = true
}
}
logger.Info().Msg("Stopped all servers")
Expand Down Expand Up @@ -1118,11 +1119,11 @@ func (app *GatewayDApp) stopGracefully(runCtx context.Context, sig os.Signal) {
span.AddEvent("GatewayD is shutdown")
span.End()

// If the code never reaches the point where the app.stopChan is used,
// it means that the server was never started. This is a manual shutdown
// by the app, so we don't need to send a signal to the other goroutines.
if earlyExit {
// Close the stop channel to notify the other goroutines to stop.
// If the server was properly initialized, the stop channel would have been
// listened on by the run command. So, we must close the stop channel to stop
// the app. Otherwise, the app is shutting down abruptly, so we don't need to
// close the stop channel.
if properlyInitialized {
app.stopChan <- struct{}{}
close(app.stopChan)
}
Expand Down

0 comments on commit 5d9801f

Please sign in to comment.