Fix Linux build and WMI NetworkStream disposal crash #3
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.
Summary
This PR fixes two critical issues:
Build System Fixes
Projects targeting
netstandard2.0andnetstandard2.1were defaulting to C# 7.3 and 8.0 respectively, despite the globalLangVersion 12.0setting. This caused build failures when using C# 9.0+ features.Changes:
LangVersion 12.0tosrc/Directory.Build.propsfor all src/ projectsLangVersion 12.0to three projects that need it:Titanis.SourceGen.csproj(netstandard2.0)Titanis.Winterop.Security.csproj(netstandard2.1)Titanis.Winterop.FileInfo.csproj(netstandard2.1)Result: Titanis now builds successfully on Linux with .NET SDK 8.0
Bug Fix: NetworkStream Disposal Race Condition
File:
src/net/Titanis.DceRpc/Client/RpcClientChannel.csMethod:
CancelRequest(PendingRequest, CancellationToken)Issue
WMI commands complete successfully but crash immediately after with:
```
Unhandled exception. System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'System.Net.Sockets.NetworkStream'.
```
Root Cause
Race condition in
CancelRequest()method. When a timeout fires or connection closes during cleanup, the cancellation callback attempts to send a CoCancel PDU, but the NetworkStream has already been disposed.Fix
Add try-catch blocks to gracefully handle
ObjectDisposedExceptionand other exceptions during cancellation. Since the request is already being cancelled, failures in sending the cancel PDU are not critical.Testing
Tested on Linux x86-64 with .NET SDK 8.0.415:
Impact