Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't set local close code when remote closes the connection #696

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions lib/src/gateway/shard_runner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,16 @@ class ShardConnection extends Stream<GatewayEvent> implements StreamSink<Send> {
_currentRateLimitEnd.complete();
_currentRateLimitEnd = Completer<void>();
});
websocket.done.then((_) => close());
websocket.done.then((_) {
_rateLimitResetTimer.cancel();
if (!_currentRateLimitEnd.isCompleted) {
_currentRateLimitEnd
// Don't report an uncaught async error for the future.
..future.ignore()
..completeError(StateError('Connection is closed'), StackTrace.current);
}
_sentController.close();
});
}

static Future<ShardConnection> connect(String gatewayUri, ShardRunner runner) async {
Expand Down Expand Up @@ -435,15 +444,9 @@ class ShardConnection extends Stream<GatewayEvent> implements StreamSink<Send> {
Future<void> close([int code = 1000]) async {
localCloseCode ??= code;

_rateLimitResetTimer.cancel();
if (!_currentRateLimitEnd.isCompleted) {
_currentRateLimitEnd
// Install an error handler so the error is not counted as uncaught.
..future.catchError((e) {})
..completeError(StateError('Connection is closed'), StackTrace.current);
}
await websocket.close(code);
await _sentController.close();

return done;
}

@override
Expand Down
Loading