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(incremental): abort async iteration when stream errors or stream is filtered #3815

Closed
wants to merge 2 commits into from

Conversation

yaacovCR
Copy link
Contributor

@yaacovCR yaacovCR commented Jan 4, 2023

Currently:

When list item completion fails for a stream with a non-nullable list:

  1. the entire list must be nulled within the given AsyncPayloadRecord
  2. any other pending AsyncPayloadRecords must be filtered
  3. async iteration powering the stream must be cancelled

Currently, the third objective is accomplished by way of the second; during AsyncPayloadRecord filtering, if a stream record is filtered and has an associated asyncIterator, its return() method is called, which should end the stream.

This can go wrong in a few ways:
A: The return() method may not exist; by specification, the return() method exists for the caller to notify the callee that the caller no longer intends to call next(), allowing for early cleanup. The method is optional, however, and so should not be relied on.
B: The return method, even if it exists, may not be set up to block any next() calls while it operates. Async generators have next and return methods that always settle in call order, but async iterables do not.

This PR adds tests addressing these scenarios and fixes the test failures.

@netlify
Copy link

netlify bot commented Jan 4, 2023

Deploy Preview for compassionate-pike-271cb3 ready!

Name Link
🔨 Latest commit 0d508d2
🔍 Latest deploy log https://app.netlify.com/sites/compassionate-pike-271cb3/deploys/63b7d0025e08e20008ed87f9
😎 Deploy Preview https://deploy-preview-3815--compassionate-pike-271cb3.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@github-actions
Copy link

github-actions bot commented Jan 4, 2023

Hi @yaacovCR, I'm @github-actions bot happy to help you with this PR 👋

Supported commands

Please post this commands in separate comments and only one per comment:

  • @github-actions run-benchmark - Run benchmark comparing base and merge commits for this PR
  • @github-actions publish-pr-on-npm - Build package from this PR and publish it on NPM

@yaacovCR yaacovCR changed the title add failing tests fix(incremental): abort async iteration when stream errors Jan 5, 2023
@yaacovCR yaacovCR requested a review from a team January 5, 2023 11:50
@yaacovCR yaacovCR added the PR: bug fix 🐞 requires increase of "patch" version number label Jan 5, 2023
@yaacovCR
Copy link
Contributor Author

yaacovCR commented Jan 5, 2023

@robrichard @graphql/graphql-js-reviewers tests fixed by adding a context object scoped to each stream that can be used to check/set error status of the entire stream.

@yaacovCR yaacovCR force-pushed the stream-test-failures branch 2 times, most recently from 507ba85 to deb73ea Compare January 5, 2023 12:35
@yaacovCR
Copy link
Contributor Author

yaacovCR commented Jan 5, 2023

Woops, initial approach worked, but was not robust, i.e. didn't end up fixing similar problem with the new Publisher.

The wrinkle is that errors outside of a stream that would lead to the entire stream being filtered should also abort async iteration. This can be managed by having a set of running streams handled by the publisher/dispatcher (currently simply stored on ExecutionContext with a path. Filtering now runs through all of those streams and if the path matches, the stream is removed from the set.

@yaacovCR yaacovCR changed the title fix(incremental): abort async iteration when stream errors fix(incremental): abort async iteration when stream errors or stream is filtered Jan 5, 2023
@yaacovCR yaacovCR force-pushed the stream-test-failures branch 3 times, most recently from 07b6036 to 1f1533f Compare January 5, 2023 18:22
Currently:

When list item completion fails for a stream with a non-nullable list:
1. the entire list must be nulled within the given AsyncPayloadRecord
2. any other pending AsyncPayloadRecords must be filtered
3. async iteration powering the stream must be cancelled

Currently, the third objective is accomplished by way of the second; during AsyncPayloadRecord filtering, if a stream record is filtered and has an associated asyncIterator, its return() method is called, which _should_ end the stream.

This can go wrong in a few ways:
A: The return() method may not exist; by specification, the return() method exists for the caller to notify the callee that the caller no longer intends to call next(), allowing for early cleanup. The method is optional, however, and so should not be relied on.
B: The return method, even if it exists, may not be set up to block any next() calls while it operates. Async generators have next and return methods that always settle in call order, but async iterables do not.
@yaacovCR
Copy link
Contributor Author

yaacovCR commented May 8, 2023

closing in favor of #3886

@yaacovCR yaacovCR closed this May 8, 2023
@yaacovCR yaacovCR deleted the stream-test-failures branch September 5, 2024 11:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: bug fix 🐞 requires increase of "patch" version number
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant