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(race): concurrent next calls with defer/stream #2975

Merged
merged 5 commits into from
Jun 2, 2021

Conversation

yaacovCR
Copy link
Contributor

@yaacovCR yaacovCR commented Mar 19, 2021

This seems to work with me for my project.

not quite sure what to do about isDone which seems to be used just when return is called (parenthetically, should that be renamed to isReturned for clarity/distinction between isDone and done attributes?)

namely, should the isDone check go up top prior to checking for the next resolved promise, within the next resolved promise check, or maybe both.

in general, not sure how we are really handling secure stopping issues, seems like -- for example -- there could be condition in which we await a promise which never resolves, but that is ok, because return has been called?

but still quite the novice with all of this async stuff

---From my opinionated perspective, I realize that graphql-js is a reference lib, and has a zero-dependency footprint, but seems like handling all these async issues (in JS in general and within graphql-js) would be easier with a Repeater-like construct (see https://repeater.js.org/, @brainkim) that could be even theoretically inlined in downsized version into js-utils.

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Mar 19, 2021

CLA Signed

The committers are authorized under a signed CLA.

@yaacovCR yaacovCR force-pushed the fix-conflicting-next branch 3 times, most recently from f70ec66 to c3f9508 Compare March 19, 2021 19:46
@yaacovCR yaacovCR changed the title attempt fix fix(race): concurrent next calls with defer/stream Mar 19, 2021
@yaacovCR
Copy link
Contributor Author

@robrichard @IvanGoncharov ready for review

@yaacovCR
Copy link
Contributor Author

Although this change suggests that _subsequentPayloads should be a set rather than an array

@yaacovCR
Copy link
Contributor Author

This PR fixes by modifying the general approach as little as possible, we still create Promise reactions to all the pending promises on each call to next.

See #2848 (comment) where I link to https://github.com/repeaterjs/repeater/blob/219a0c8faf2c2768d234ecfe8dd21d455a4a98fe/packages/repeater/src/repeater.ts#L687 that uses a different approach to convert all pending promises to async iterables (which each yield one value) and then combining those iterables in settle order.

If you would be more open to that type of approach, I can try to see if I can work to extract it (maybe with the help of @brainkim)

@robrichard
Copy link
Contributor

@yaacovCR thanks again for your help on this. I'm not tied to the current approach. I think a generic well-tested jsutil that can combine and race promises and async iterables makes sense.

@yaacovCR
Copy link
Contributor Author

@robrichard @IvanGoncharov I think the best path forward so as to not lose steam/forward momentum with any experimenters, would be to merge this bug fix that keeps the existing approach, and then as a separate PR, see if myself or @brainkim is able to work something else out in a refactor.

@IvanGoncharov IvanGoncharov added the stream/defer Issues/PRs related to experimental steam/defer support label Mar 31, 2021
yaacovCR added a commit to ardatan/graphql-tools that referenced this pull request Apr 21, 2021
tests failing, on the bright side, it means that our test coverage is meaningful :)

at least some tests are failing because of a bug in current defer/stream implementation, see graphql/graphql-js#2975
yaacovCR added a commit to ardatan/graphql-tools that referenced this pull request May 1, 2021
@yaacovCR
Copy link
Contributor Author

yaacovCR commented Jun 2, 2021

Would this be accepted if rebased? graphql tools stitching support uses patch package to apply this fix....

@robrichard
Copy link
Contributor

@yaacovCR I'm planning to spend some time refactoring the dispatcher to a generic jsutil that can be more easily tested and handle all the edge cases

@yaacovCR
Copy link
Contributor Author

yaacovCR commented Jun 2, 2021

Sure but until then can we merge it so the bug is fixed

@yaacovCR
Copy link
Contributor Author

yaacovCR commented Jun 2, 2021

Meaning prior to next experimental release it would be nice if fixed somehow with this PR if not a refactor

@robrichard robrichard merged commit c393ab3 into graphql:defer-stream Jun 2, 2021
robrichard added a commit that referenced this pull request Feb 2, 2022
* fix(race): concurrent next calls

* refactor test

* use invariant

* disable eslint error

* fix
robrichard added a commit that referenced this pull request Feb 7, 2022
* fix(race): concurrent next calls

* refactor test

* use invariant

* disable eslint error

* fix
robrichard added a commit that referenced this pull request Feb 7, 2022
* fix(race): concurrent next calls

* refactor test

* use invariant

* disable eslint error

* fix
robrichard added a commit that referenced this pull request Feb 23, 2022
* fix(race): concurrent next calls

* refactor test

* use invariant

* disable eslint error

* fix
robrichard added a commit that referenced this pull request Feb 23, 2022
* fix(race): concurrent next calls

* refactor test

* use invariant

* disable eslint error

* fix
robrichard added a commit that referenced this pull request Feb 23, 2022
* fix(race): concurrent next calls

* refactor test

* use invariant

* disable eslint error

* fix
robrichard added a commit that referenced this pull request Mar 7, 2022
* fix(race): concurrent next calls

* refactor test

* use invariant

* disable eslint error

* fix
robrichard added a commit that referenced this pull request Mar 7, 2022
* fix(race): concurrent next calls

* refactor test

* use invariant

* disable eslint error

* fix
robrichard added a commit that referenced this pull request Apr 4, 2022
* fix(race): concurrent next calls

* refactor test

* use invariant

* disable eslint error

* fix
robrichard added a commit that referenced this pull request Apr 13, 2022
* fix(race): concurrent next calls

* refactor test

* use invariant

* disable eslint error

* fix
robrichard added a commit that referenced this pull request Apr 20, 2022
* fix(race): concurrent next calls

* refactor test

* use invariant

* disable eslint error

* fix
robrichard added a commit that referenced this pull request Apr 20, 2022
* fix(race): concurrent next calls

* refactor test

* use invariant

* disable eslint error

* fix
robrichard added a commit that referenced this pull request Apr 27, 2022
* fix(race): concurrent next calls

* refactor test

* use invariant

* disable eslint error

* fix
robrichard added a commit that referenced this pull request May 5, 2022
* fix(race): concurrent next calls

* refactor test

* use invariant

* disable eslint error

* fix
robrichard added a commit that referenced this pull request May 5, 2022
* fix(race): concurrent next calls

* refactor test

* use invariant

* disable eslint error

* fix
robrichard added a commit that referenced this pull request May 13, 2022
* fix(race): concurrent next calls

* refactor test

* use invariant

* disable eslint error

* fix
robrichard added a commit that referenced this pull request May 23, 2022
* fix(race): concurrent next calls

* refactor test

* use invariant

* disable eslint error

* fix
robrichard added a commit that referenced this pull request May 26, 2022
* fix(race): concurrent next calls

* refactor test

* use invariant

* disable eslint error

* fix
robrichard added a commit that referenced this pull request May 26, 2022
* fix(race): concurrent next calls

* refactor test

* use invariant

* disable eslint error

* fix
robrichard added a commit that referenced this pull request Jun 13, 2022
* fix(race): concurrent next calls

* refactor test

* use invariant

* disable eslint error

* fix
robrichard added a commit that referenced this pull request Jun 21, 2022
* fix(race): concurrent next calls

* refactor test

* use invariant

* disable eslint error

* fix
robrichard added a commit that referenced this pull request Jun 22, 2022
* fix(race): concurrent next calls

* refactor test

* use invariant

* disable eslint error

* fix
robrichard added a commit that referenced this pull request Jun 23, 2022
* fix(race): concurrent next calls

* refactor test

* use invariant

* disable eslint error

* fix
robrichard added a commit that referenced this pull request Aug 3, 2022
* fix(race): concurrent next calls

* refactor test

* use invariant

* disable eslint error

* fix
robrichard added a commit that referenced this pull request Aug 3, 2022
* fix(race): concurrent next calls

* refactor test

* use invariant

* disable eslint error

* fix
robrichard added a commit that referenced this pull request Aug 15, 2022
* fix(race): concurrent next calls

* refactor test

* use invariant

* disable eslint error

* fix
robrichard added a commit that referenced this pull request Aug 19, 2022
* fix(race): concurrent next calls

* refactor test

* use invariant

* disable eslint error

* fix
robrichard added a commit that referenced this pull request Aug 19, 2022
* fix(race): concurrent next calls

* refactor test

* use invariant

* disable eslint error

* fix
robrichard added a commit that referenced this pull request Aug 23, 2022
* fix(race): concurrent next calls

* refactor test

* use invariant

* disable eslint error

* fix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stream/defer Issues/PRs related to experimental steam/defer support
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants