Skip to content

Avoid deadlock when a schema filter depends on ISerializerDataContractResolver - #4210

Merged
martincostello merged 2 commits into
domaindrivendev:masterfrom
DevKaurav-14:fix-schema-filter-resolver-deadlock
Oct 19, 2026
Merged

martincostello merged 2 commits into
domaindrivendev:masterfrom
DevKaurav-14:fix-schema-filter-resolver-deadlock

Conversation

@DevKaurav-14

@DevKaurav-14 DevKaurav-14 commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #4207

Since 10.3.0 (#3998), the factories that register ISerializerDataContractResolver read IOptions.Value when the resolver is created. Schema filters are created by ConfigureSchemaGeneratorOptions.Configure while those same options are being built, so a filter whose constructor takes ISerializerDataContractResolver re-enters the options configuration and the swagger.json request deadlocks.

This change makes the resolvers read the options on first use instead of at construction:

  • JsonSerializerDataContractResolver and NewtonsoftDataContractResolver each get an internal constructor that takes IOptions. The value is read in IsNullable, during schema generation, after configuration has finished.
  • The AddSwaggerGen and AddSwaggerGenNewtonsoftSupport factories pass IOptions instead of its Value.
  • The existing public constructors are unchanged; they wrap the given options with Options.Create, so there is no public API change and code that constructs a resolver directly behaves as before.

Tests: one test per resolver registers a schema filter that depends on ISerializerDataContractResolver and resolves IOptions.Value. Because the bug is a hang rather than an exception, the resolution runs on a separate task with a 30 second timeout. Both tests time out on net8.0, net9.0 and net10.0 without the fix and pass with it.

I ran the full test suite locally on macOS (arm64) with SDK 10.0.402. Everything passes except the three Playwright UITests, which could not install their browser dependencies on my machine.

PR Checklist

  • I have read and followed the Contributing guide.
  • I have added tests for my changes where appropriate.
  • I have the experience and knowledge necessary to understand, review, and validate all content in this PR.
  • This PR has content that I did not fully write myself.

@martincostello martincostello changed the title Fix #4207: avoid deadlock when a schema filter depends on ISerializerDataContractResolver Avoid deadlock when a schema filter depends on ISerializerDataContractResolver Oct 19, 2026
Remove comments and shorten timeouts.

Co-authored-by: Martin Costello <martin@martincostello.com>
@martincostello martincostello added this to the v10.3.1 milestone Oct 19, 2026
@codecov

codecov Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.66667% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.77%. Comparing base (1e2b358) to head (544e863).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
.../SchemaGenerator/NewtonsoftDataContractResolver.cs 83.33% 0 Missing and 1 partial ⚠️
...emaGenerator/JsonSerializerDataContractResolver.cs 85.71% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4210      +/-   ##
==========================================
+ Coverage   91.57%   91.77%   +0.20%     
==========================================
  Files         108      108              
  Lines        4057     4063       +6     
  Branches      909      909              
==========================================
+ Hits         3715     3729      +14     
+ Misses        198      189       -9     
- Partials      144      145       +1     
Flag Coverage Δ
Linux 91.77% <86.66%> (+0.20%) ⬆️
Windows 91.77% <86.66%> (+0.20%) ⬆️
macOS 91.77% <86.66%> (+0.20%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@martincostello
martincostello enabled auto-merge (squash) October 19, 2026 12:25
@martincostello
martincostello merged commit 6b7491b into domaindrivendev:master Oct 19, 2026
13 of 14 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for your contribution @DevKaurav-14 - the changes from this pull request have been published as part of version 10.3.1 📦, which is now available from NuGet.org 🚀

This was referenced Oct 19, 2026
This was referenced Oct 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: A schema filter taking ISerializerDataContractResolver in its constructor makes the swagger.json request hang (regression in 10.3.0)

2 participants