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

fix(api): fix subscription race condition from previous connection close #2405

Merged
merged 2 commits into from
Nov 23, 2022
Merged

fix(api): fix subscription race condition from previous connection close #2405

merged 2 commits into from
Nov 23, 2022

Conversation

ragingsquirrel3
Copy link
Contributor

This PR fixes a race condition in API GraphQL subscriptions that is causing auth integ tests to fail. The issue arises when establishing a subscription on a connection that is in the process of being closed, causing an error from trying to send over a closed socket. This PR fixes it by moving some async logic so that the check of connection open/closed while establishing a subscription happens later and will open a new connection.

This fix is a little hacky and would usually have some more unit tests. I didn't do that here because 1) all this will be replaced by subscription state machine 2) the auth integ tests are already serving a sort of check here.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@ragingsquirrel3 ragingsquirrel3 requested a review from a team as a code owner November 22, 2022 22:32
Comment on lines 455 to 463

// No-op if already connected.
// Run after generating the connection message to account for connection
// closed while generating message.
await init();

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// No-op if already connected.
// Run after generating the connection message to account for connection
// closed while generating message.
await init();
if (_channel == null) {
return _sendSubscriptionRegistrationMessage(request);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pushed a change w this suggestion (but kept await init()).

@ragingsquirrel3 ragingsquirrel3 merged commit 4aa2a63 into aws-amplify:next Nov 23, 2022
@ragingsquirrel3 ragingsquirrel3 deleted the feat/api-sub-fix2 branch November 23, 2022 16:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants