Skip to content

Commit

Permalink
fix a randomly occurring bug where switching server hangs and times out
Browse files Browse the repository at this point in the history
  • Loading branch information
robinbraemer committed Aug 9, 2020
1 parent 9f970c5 commit 993eb79
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
14 changes: 11 additions & 3 deletions pkg/proxy/session_backend_login.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,18 @@ func (b *backendLoginSessionHandler) activated() {
b.listenDoneCtx = make(chan struct{})
go func() {
select {
case <-b.requestCtx.Done():
b.requestCtx.result(nil, errors.New(
"context deadline exceeded while logging into backend server"))
case <-b.listenDoneCtx:
case <-b.requestCtx.Done():
// We must check again since request context
// may be canceled before deactivated() was run.
select {
case <-b.listenDoneCtx:
return
default:
b.requestCtx.result(nil, errors.New(
"context deadline exceeded while logging into backend server"))
b.serverConn.disconnect()
}
}
}()
}
Expand Down
21 changes: 18 additions & 3 deletions pkg/proxy/session_backend_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,18 @@ func (b *backendTransitionSessionHandler) activated() {
b.listenDoneCtx = make(chan struct{})
go func() {
select {
case <-b.requestCtx.Done():
b.requestCtx.result(nil, errors.New(
"context deadline exceeded while transitioning player to backend server"))
case <-b.listenDoneCtx:
case <-b.requestCtx.Done():
// We must check again since request context
// may be canceled before deactivated() was run.
select {
case <-b.listenDoneCtx:
return
default:
b.requestCtx.result(nil, errors.New(
"context deadline exceeded while transitioning player to backend server"))
b.serverConn.disconnect()
}
}
}()
}
Expand Down Expand Up @@ -169,6 +177,13 @@ func (b *backendTransitionSessionHandler) handleJoinGame(p *packet.JoinGame) {
return
}

if previousServer == nil {
zap.S().Infof("%s initial server %q", b.serverConn.player, b.serverConn.server.ServerInfo().Name())
} else {
zap.S().Infof("%s moved from %q to %q", b.serverConn.player, previousServer.ServerInfo().Name(),
b.serverConn.server.ServerInfo().Name())
}

// Strap on the ClientPlaySessionHandler if required.
b.serverConn.player.minecraftConn.mu.Lock()
playHandler, ok := b.serverConn.player.minecraftConn.sessionHandler.(*clientPlaySessionHandler)
Expand Down

0 comments on commit 993eb79

Please sign in to comment.