Fix ObjectDisposedException race in DataStreamsWriter disposal#8758
Conversation
Execution-Time Benchmarks Report ⏱️Execution-time results for samples comparing This PR (8758) and master. ✅ No regressions detected - check the details below Full Metrics ComparisonFakeDbCommand
HttpMessageHandler
Comparison explanationExecution-time benchmarks measure the whole time it takes to execute a program, and are intended to measure the one-off costs. Cases where the execution time results for the PR are worse than latest master results are highlighted in **red**. The following thresholds were used for comparing the execution times:
Note that these results are based on a single point-in-time result for each branch. For full results, see the dashboard. Graphs show the p99 interval based on the mean and StdDev of the test run, as well as the mean value of the run (shown as a diamond below the graph). Duration chartsFakeDbCommand (.NET Framework 4.8)gantt
title Execution time (ms) FakeDbCommand (.NET Framework 4.8)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8758) - mean (74ms) : 71, 76
master - mean (74ms) : 71, 78
section Bailout
This PR (8758) - mean (79ms) : 76, 82
master - mean (78ms) : 75, 81
section CallTarget+Inlining+NGEN
This PR (8758) - mean (1,097ms) : 1051, 1144
master - mean (1,094ms) : 1053, 1135
FakeDbCommand (.NET Core 3.1)gantt
title Execution time (ms) FakeDbCommand (.NET Core 3.1)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8758) - mean (117ms) : 112, 121
master - mean (116ms) : 110, 121
section Bailout
This PR (8758) - mean (117ms) : 113, 122
master - mean (114ms) : 111, 117
section CallTarget+Inlining+NGEN
This PR (8758) - mean (789ms) : 769, 809
master - mean (786ms) : 770, 803
FakeDbCommand (.NET 6)gantt
title Execution time (ms) FakeDbCommand (.NET 6)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8758) - mean (104ms) : 99, 109
master - mean (104ms) : 98, 111
section Bailout
This PR (8758) - mean (103ms) : 100, 105
master - mean (102ms) : 98, 107
section CallTarget+Inlining+NGEN
This PR (8758) - mean (945ms) : 906, 984
master - mean (947ms) : 914, 980
FakeDbCommand (.NET 8)gantt
title Execution time (ms) FakeDbCommand (.NET 8)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8758) - mean (99ms) : 96, 103
master - mean (100ms) : 97, 102
section Bailout
This PR (8758) - mean (103ms) : 99, 106
master - mean (103ms) : 99, 107
section CallTarget+Inlining+NGEN
This PR (8758) - mean (820ms) : 785, 855
master - mean (823ms) : 780, 865
HttpMessageHandler (.NET Framework 4.8)gantt
title Execution time (ms) HttpMessageHandler (.NET Framework 4.8)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8758) - mean (200ms) : 194, 207
master - mean (200ms) : 195, 205
section Bailout
This PR (8758) - mean (205ms) : 199, 210
master - mean (205ms) : 201, 209
section CallTarget+Inlining+NGEN
This PR (8758) - mean (1,206ms) : 1159, 1253
master - mean (1,204ms) : 1159, 1249
HttpMessageHandler (.NET Core 3.1)gantt
title Execution time (ms) HttpMessageHandler (.NET Core 3.1)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8758) - mean (289ms) : 281, 296
master - mean (289ms) : 282, 297
section Bailout
This PR (8758) - mean (290ms) : 286, 293
master - mean (290ms) : 285, 295
section CallTarget+Inlining+NGEN
This PR (8758) - mean (969ms) : 952, 985
master - mean (976ms) : 952, 1001
HttpMessageHandler (.NET 6)gantt
title Execution time (ms) HttpMessageHandler (.NET 6)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8758) - mean (284ms) : 279, 289
master - mean (281ms) : 274, 287
section Bailout
This PR (8758) - mean (283ms) : 276, 291
master - mean (281ms) : 276, 286
section CallTarget+Inlining+NGEN
This PR (8758) - mean (1,163ms) : 1125, 1201
master - mean (1,165ms) : 1129, 1201
HttpMessageHandler (.NET 8)gantt
title Execution time (ms) HttpMessageHandler (.NET 8)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8758) - mean (280ms) : 270, 289
master - mean (281ms) : 274, 287
section Bailout
This PR (8758) - mean (279ms) : 273, 284
master - mean (280ms) : 274, 286
section CallTarget+Inlining+NGEN
This PR (8758) - mean (1,043ms) : 999, 1086
master - mean (1,042ms) : 1003, 1082
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
BenchmarksBenchmark execution time: 2026-06-05 14:22:47 Comparing candidate commit 97e7355 in PR branch Found 0 performance improvements and 1 performance regressions! Performance is the same for 71 metrics, 0 unstable metrics, 59 known flaky benchmarks, 67 flaky benchmarks without significant changes.
|
andrewlock
left a comment
There was a problem hiding this comment.
Thanks, TIL that not disposing these is safe as long as you never call AvailableWaitHandle/WaitHandle 👍
Summary of changes
Stop disposing the
_flushSemaphoreand_drainSignalsynchronization primitives inDataStreamsWriter.DisposeAsync.Reason for change
Flaky CI failures (e.g.
DataStreamsMonitoringRabbitMQTests) whereCheckBuildLogsForErrorsfinds:This is a third variant of the disposal race partially addressed by #7968 and #7984.
FlushAndCloseAsyncwaits for both the process and flush tasks, but with a 1-second fallback that must exist so process exit can never hang. On an overloaded CI host, the flush task can still be insideFlushAggregatorAsync(blocked in_api.SendAsync) when the fallback fires.DisposeAsyncthen disposes_flushSemaphore, and when the send returns, thefinallyblock's_flushSemaphore.Release()throwsObjectDisposedException, faulting_flushTaskand logging a spurious[Error]during shutdown. The same race exists latently for_drainSignalviaProcessQueueLoop.The 1-second fallback is load-bearing, so the race can't be closed by waiting longer.
Implementation details
SemaphoreSlimandManualResetEventSlimonly hold an unmanaged resource (a lazily-created wait handle) if theirAvailableWaitHandle/WaitHandleproperty is accessed. This class never does — it only usesWaitAsync/Wait/Release/Set/Reset/IsSet. SoDispose()here is a no-op apart from arming theObjectDisposedException. Removing bothDispose()calls eliminates the race at its source with no resource leak. Added a comment so the calls aren't reintroduced.Test coverage
Covered by existing DSM tests; this removes the spurious shutdown error that
CheckBuildLogsForErrorswas flagging.Other details