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

Prevent canceled @stream tasks from breaking subsequent @stream query #5712

Merged
merged 2 commits into from
Jan 30, 2023

Conversation

atykhyy
Copy link
Contributor

@atykhyy atykhyy commented Jan 23, 2023

This fix largely prevents canceled @stream tasks from breaking subsequent @stream queries.

When a query containing deferred @stream is canceled (e.g. due to http connection closing), DeferResultStream.GetAsyncEnumerator() disposes the work state owner, invoking DeferredWorkState.Reset(), before the tasks waiting for items from async enumerators being @stream'ed are canceled. When these tasks are canceled, they add IQueryResults with Errors set to OperationCanceledException to the freshly reset DeferredWorkState. The next query which rents this DeferredWorkState picks up these stale results and quits in DeferredWorkState.TryDequeueResultsAsync() after sending its initial result, so that the client invoking the query receives an empty result with hasNext:false and no @stream items.

ETA: this change doesn't fix the problem completely, but it does reduce the window of the underlying race condition very substantially. Instead of every other subscription being truncated as described above, I now observe truncation rarely and sporadically.

@CLAassistant
Copy link

CLAassistant commented Jan 23, 2023

CLA assistant check
All committers have signed the CLA.

@michaelstaib michaelstaib merged commit bc5f432 into ChilliCream:main Jan 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants