Skip to content

Conversation

@basti1302
Copy link
Contributor

@basti1302 basti1302 commented Jun 27, 2019

Not sure if this list is still maintained or not, but if it is, the graphql-subscriptions should 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 calls pullValue(), which in turn creates a promise and puts that promise's resolve function 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 the then of that promise is not connected to the async context of the call to pushValue.

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_hooks internally.

As a user of async_hooks I would expect that everything that is triggered by publishing the event (that is, calling pushValue) happens in that context. The module graphql-subscriptions breaks that expectation.

gireeshpunathil pushed a commit that referenced this pull request Oct 17, 2019
Add graphql-subscriptions to list of modules
breaking async continuity

PR-URL: #311

Reviewed-By: Stephen Belanger <[email protected]>
Reviewed-By: Gireesh Punathil <[email protected]>
@gireeshpunathil
Copy link
Member

landed as 0d19067

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.

3 participants