Repository navigation
Conversation
Member
|
beep boop, agent be gone |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #648.
reconnect()runsdoReconnectwithcontext.Background(), so aCloseduring the reconnect backoff has no effect: the loop's only cancellation point (ctx.Done()while waiting on the backoff timer) never fires, and the gateway reconnects right after being closed. For shard managers this also means anOpenracing with the close has to fight the reconnect goroutine over the connection.This PR gives each
reconnect()run its own cancelable context, registered on the gateway (same pattern asstartHeartbeat/cancelHeartbeat):CloseWithCodecancels a pending reconnect loop after canceling the heartbeat, soCloseis honored during the backoffdoReconnectreturns immediately whenopenfails with a canceled context (e.g. the gateway was closed mid-dial) instead of continuing the backoff loopCloseHandlerwith a fake failurereconnect()cancels the previous one, and the deferred cleanup only clears the registration it ownsTests
Added
gateway/gateway_reconnect_close_test.go:TestCloseCancelsPendingReconnectverifies thatClosecancels a registered reconnect context (the loop's cancellation point)go build ./...,go vet ./gatewayandgo test ./gateway -raceall pass.