Skip to content

Commit

Permalink
GracefulTermination when GameServer get deleted (#3141)
Browse files Browse the repository at this point in the history
Current SDKGracefulTermination implementation uses gsStateChannel which get updated in sendGameServerUpdate. However, when GameServer gets deleted (e.g. when fleet updates), sendGameServerUpdate will not be triggered because updateState() will skip update in this case (gs.IsBeingDeleted() returns true). Therefore SDK server will blocks even SDK.Shutdown() has been called.

This PR solves the issue by explicitly updating gsStateChannel when

* GS is being deleted
* Current SDK server state is Shutdown
* State of GS is not Shutdown.
  • Loading branch information
qizichao-dm committed May 11, 2023
1 parent ae8c714 commit 83d77cb
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/sdkserver/sdkserver.go
Expand Up @@ -342,6 +342,14 @@ func (s *SDKServer) updateState(ctx context.Context) error {
// If we are currently in shutdown/being deleted, there is no escaping.
if gs.IsBeingDeleted() {
s.logger.Debug("GameServerState being shutdown. Skipping update.")

// Explicitly update gsStateChannel if current state is Shutdown since sendGameServerUpdate will not triggered.
if runtime.FeatureEnabled(runtime.FeatureSDKGracefulTermination) && s.gsState == agonesv1.GameServerStateShutdown && gs.Status.State != agonesv1.GameServerStateShutdown {
go func() {
s.gsStateChannel <- agonesv1.GameServerStateShutdown
}()
}

return nil
}

Expand Down

0 comments on commit 83d77cb

Please sign in to comment.