-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[QUIC] Fix native crashes and heap corruption #74611
Conversation
Tagging subscribers to this area: @dotnet/ncl Issue DetailsThere were races between disposing SendBuffers and MsQuic handles and using them from parallel threads. Most prominent in stress tests in configuration After the change, I didn't see any crashes in stress in a couple of hours, will keep them running in the meantime. Change has no impact on perf. Fixes #72696
|
} | ||
} | ||
|
||
public void SafeCall(Action<MsQuicSafeHandle> call) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This generally should not be need. runtime would automatically grab reference on pinvoke if we pass in safe handle. .... But we don't. It seems like we lost that when switching to generated API. This is all hidden as we pass the safe handle around everywhere and then we don't use it when we should and we pass IntPtr to quic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not thrilled about the fact that this leads to closure allocation per call in many cases (StreamSend, EnableReceive, ....). I think we should consider (possibly in follow-up) either
- writing wrappers for MsQuicApi which does this for us (i.e. duplicating what P/Invoke does)
- look for a way to have the source generator generate them for us.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with both comments, and I believe we should look for a way to solve this in generated API, otherwise it is not sustainable. If we would be able to do that in time, it would be ideal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM for now, we can follow up with interop improvements in .NET 8.0
@@ -90,6 +90,7 @@ public sealed partial class QuicStream | |||
} | |||
}; | |||
private MsQuicBuffers _sendBuffers = new MsQuicBuffers(); | |||
private object _sendBuffersLock = new object(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😢
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discussed offline; it's either this or make MsQuicBuffers class instead of struct
There's a branch with a different approach to safe calls via "generated-like" interop; discussed with @ManickaP that it will be her choice with which solution to proceed UPD: opened alternative PR with that branch: #74669 |
Tagging subscribers to this area: @dotnet/ncl Issue DetailsThere were races between disposing SendBuffers and MsQuic handles and using them from parallel threads. Most prominent in stress tests in configuration After the change, I didn't see any crashes in stress in a couple of hours, will keep them running in the meantime. Change has no impact on perf. Fixes #72696
|
Closing in favor of #74669 |
…terop (dotnet#74669) * Send buffers and handles crash fixes * Add generated-like interop * Apply PR feedback from dotnet#74611 * Change asserts * Feedback + moved native methods to their own file * PR feedback Co-authored-by: ManickaP <mapichov@microsoft.com>
…terop (#74669) (#75192) * Send buffers and handles crash fixes * Add generated-like interop * Apply PR feedback from #74611 * Change asserts * Feedback + moved native methods to their own file * PR feedback Co-authored-by: ManickaP <mapichov@microsoft.com> Co-authored-by: ManickaP <mapichov@microsoft.com>
There were races between disposing SendBuffers and MsQuic handles and using them from parallel threads. Most prominent in stress tests in configuration
-cancelRate 1 -ops 9
(POST Duplex Dispose).After the change, I didn't see any crashes in stress in a couple of hours, will keep them running in the meantime.
Change has no impact on perf.
Fixes #72696