Skip to content

Fix pooled operation contexts being reused while deferred resolvers still run - #10519

Merged
michaelstaib merged 2 commits into
mainfrom
mst/fix-defer-context-pooling
Oct 20, 2026
Merged

michaelstaib merged 2 commits into
mainfrom
mst/fix-defer-context-pooling

Conversation

@michaelstaib

Copy link
Copy Markdown
Member

When a request was aborted while a @defer branch was still running, its operation context went back to the pool while the deferred resolvers still used it. The next request could rent that context, finish early with missing data, and return a Cannot return null for non-nullable field. error from the old request. Operation contexts now count the tasks created from them, and the pool discards a context that still has tasks outstanding. The defer task also waits for its tasks to be returned before it resets its context.

# request 1, aborted while `slow` runs
{ fast ... @defer { slow } }

# request 2, before this fix
# {"errors":[{"message":"Cannot return null for non-nullable field.","path":["slow"]}],"data":{"fast":"fast-value"}}
{ fast }

Copilot AI balanced review requested due to automatic review settings October 9, 2026 00:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Patch coverage

96.5% of changed lines covered (83/86)

File Covered Changed Patch %
…/src/Types/Execution/Processing/OperationContext.Pooling.cs 41 44 93.2% 🟡
…/DependencyInjection/InternalServiceCollectionExtensions.cs 3 3 100.0% 🟢
…/src/Types/Execution/Processing/OperationContext.Execution.cs 6 6 100.0% 🟢
…/src/Types/Execution/Processing/Tasks/BatchResolverTask.cs 16 16 100.0% 🟢
…/Core/src/Types/Execution/Processing/Tasks/DeferTask.cs 1 1 100.0% 🟢
…/src/Types/Execution/Processing/Tasks/ResolverTask.Execute.cs 2 2 100.0% 🟢
…/src/Types/Execution/Processing/Tasks/ResolverTask.Pooling.cs 14 14 100.0% 🟢
Uncovered changed lines (JSON)
{
  "sha": "c9d2f8034273fd304f654c55159369dbc297327e",
  "files": [
    { "path": "src/HotChocolate/Core/src/Types/Execution/Processing/OperationContext.Pooling.cs", "ranges": [[124, 126]] }
  ]
}

Project coverage: 59.1% (312353/528635 lines)

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.

2 participants