-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Handle failed subscription payloads #7866
Merged
tninesling
merged 4 commits into
main
from
tninesling/handle-failed-subscription-payloads
Apr 5, 2024
Merged
Handle failed subscription payloads #7866
tninesling
merged 4 commits into
main
from
tninesling/handle-failed-subscription-payloads
Apr 5, 2024
Conversation
This file contains 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
✅ Deploy Preview for apollo-server-docs ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
tninesling
changed the title
Tninesling/handle failed subscription payloads
Handle failed subscription payloads
Apr 4, 2024
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. |
IvanGoncharov
approved these changes
Apr 5, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like a simple fit to me 👍
Merged
tninesling
pushed a commit
that referenced
this pull request
Apr 15, 2024
This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated. # Releases ## @apollo/server-integration-testsuite@4.10.3 ### Patch Changes - Updated dependencies \[[`5f335a5`](5f335a5)]: - @apollo/server@4.10.3 ## @apollo/server@4.10.3 ### Patch Changes - [#7866](#7866) [`5f335a5`](5f335a5) Thanks [@tninesling](https://github.com/tninesling)! - Catch errors thrown by subscription generators, and gracefully clean up the subscription instead of crashing. Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Currently, the error handling for subscription events is not well-defined in the GraphQL spec, but that doesn't mean we shouldn't handle them! The existing behavior is that an error thrown from a subscription's generator will go uncaught and crash the whole server.
For a transient failure, it may be preferable for consumers that we simply return an error response and continue waiting for more data from the iterator, in case the producer recovers and resumes producing valid data. However, Node's AsyncGenerator terminates once an error is thrown, even if you manually loop calling
iterator.next()
.This change wraps the iterator consumption in a
try/catch
and closes the subscription when an error is encountered. Propagating the error up to the subscriber will allow them to decide if they need to resubscribe or not, in the case of a transient error.