Port StreamWriter leaveOpen:true dispose fix (runtime#125189) — Impact Assessment#1
Draft
ViveliDuCh wants to merge 1 commit into
Draft
Port StreamWriter leaveOpen:true dispose fix (runtime#125189) — Impact Assessment#1ViveliDuCh wants to merge 1 commit into
ViveliDuCh wants to merge 1 commit into
Conversation
Port changes from dotnet/runtime#125189 into the VMR. Fixes StreamWriter keeping working after Dispose() when leaveOpen:true. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Goal
Assess whether dotnet/runtime#125189 — which fixes
StreamWriter.Dispose()not setting_disposed = truewhenleaveOpen: true— should be merged intodotnet/runtime, by porting the changes into this VMR fork and measuring the blast radius across the entire .NET codebase.Upstream issue: dotnet/runtime#89646
What this branch contains
All 5 file changes from runtime#125189, ported into
src/runtime/:StreamWriter.cs_closablemoved from outer guard to innerif, so_disposed = trueexecutes unconditionallyConsole.csNonClosableStreamWritersubclass preventsConsole.Out/Console.Errorfrom breakingStreamWriter.CloseTests.csleaveOpen: truedisposalStreamWriter.DisposeAsync.csDisposeAsynctests for disposed stateStreamReaderTests.csStreamReaderconsistencyInvestigation Summary
More details in: https://gist.github.com/ViveliDuCh/e6e796a88f14d8a9918b67b06e3fe431
VMR-wide codebase search (25+ repos, 178,000+ files)
StreamWriterwithleaveOpen: true(9 production, 37 test)StreamWriter)Test results
Core test suites (directly exercise the fix):
Extended test suites (exercise
leaveOpenconsumers found in codebase search):Previously blocked — now unblocked (after disk resize + repo bootstrapping):
Combined: 18,874 total tests | 18,729 passed | 0 regressions
The 13 Razor Tool failures are
SdkTestContextinitialization errors (missing redist build artifact) — the 2 ServerCommand tests that directly exerciseStreamWriter+leaveOpenboth passed.Key findings
Console.Out/Console.Error(for 12+ years), which the PR addresses withNonClosableStreamWriter.StreamReaderhas always set_disposed = trueregardless ofleaveOpen. This fix makesStreamWriterconsistent.ObjectDisposedExceptionat the exact call site — no silent corruption.Reviewer concerns addressed
leaveOpenwas introduced. Our finding: the measured blast radius is zero across the VMR, the correctness value is clear (IDisposable contract consistency withStreamReader), and there is no evidence of problems.Console.Out/Console.Errorsuggests widespread dependents. Our finding: the VMR-wide search shows zero other code depending on this bug. The Console dependency was the sole exception, not the rule.Recommendation
✅ Merge the fix into
dotnet/runtime.The change is correct, the measured impact is zero within .NET's own codebase (18,874 tests across 9 suites, 0 regressions — including all previously blocked suites now unblocked and passing), and the risk to external consumers is bounded by Preview 3 feedback and a trivial workaround. Not fixing it preserves a 12-year inconsistency between
StreamWriterandStreamReaderthat undermines theIDisposablecontract.Suggested follow-up actions
dotnet/docsStreamWriterAppContextswitch as a temporary compat bridge