Add graphql-subscriptions to list of modules breaking async continuity #311
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.
Not sure if this list is still maintained or not, but if it is, the
graphql-subscriptionsshould be on it. It has a custom queueing mechanism.It works roughly like this: GraphQL subscriptions use an instance of the async iterator. The subscription engine waits for new events by calling
next()on it, which internally callspullValue(), which in turn creates a promise and puts that promise'sresolvefunction into an internal queue called pullQueue (here).When a new event is published via
pushValue, the resolve function is pulled out of that queue and called with the event that is to be published. This is where async continuity is lost, in particular, the execution of thethenof that promise is not connected to the async context of the call topushValue.My guess is that the reason for this is that the promise has already been created earlier, outside of that context. The different approaches to promises discussed in othiym23/node-continuation-local-storage#64 might be relevant here. As a matter of fact, I stumbled upon this while using https://github.com/jeff-lewis/cls-hooked, which relies on
async_hooksinternally.As a user of
async_hooksI would expect that everything that is triggered by publishing the event (that is, callingpushValue) happens in that context. The modulegraphql-subscriptionsbreaks that expectation.