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

Queries that use a DataLoader executed by a second event of a given subscription returns stale data from the initial event #1210

Closed
rafd123 opened this issue Nov 18, 2019 · 0 comments
Assignees
Milestone

Comments

@rafd123
Copy link
Contributor

rafd123 commented Nov 18, 2019

Describe the bug
When using subscriptions in conjunction with DataLoaders, queries of subsequent subscription events return stale data.

To Reproduce

  1. Create a query that has a field resolver that leverages a DataLoader
  2. Create a subscription where the field in step 1. is included in the graph
  3. Create a mutation that modifies the underlying data and triggers the subscription in Step 2.
  4. Run the app and subscribe to the subscription in step 2., referencing the field that leverages the DataLoader in Step 1.
  5. With the app running, invoke the mutation in step 3. multiple times with different data each time.
  6. Every time the subscription is triggered, the query run in Step 4. will return stale data after the first event.

The following repo demonstrates the issue: https://github.com/rafd123/SubscriptionIssueRepro

2019-11-16-17 44 05

Expected behavior
When the subscription event is triggered, its query should reflect the current state of the data.

Desktop (please complete the following information):

  • OS: Windows
  • Version 10

Additional context
The issue appears to be caused by the fact that the subscription event queries end up sharing the same service scope as the initial request to create the subscription instead of having their own scope.

Using the example repo, this is what the service scope looks like during the initial subscription event query:

2019-11-16-18 33 43

This is what the service scope looks like after subsequent subscription event queries; note the DataLoader from the initial query is in the scope with the original data:

2019-11-16-18 35 14

2019-11-16-18 39 02

rafd123 added a commit to rafd123/hotchocolate that referenced this issue Nov 18, 2019
…stContext

Doing so ensures that any queries that use the cloned context get their
own scoped service instances instead of using the scoped service instances
of the original RequestContext.

This solves the issue of inadvertently having subscription event queries
use the service scope of the originating long-lived subscription request.

See issue ChilliCream#1210
@michaelstaib michaelstaib added this to the 10.3.0 milestone Nov 18, 2019
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

No branches or pull requests

2 participants