-
Notifications
You must be signed in to change notification settings - Fork 5.2k
catch exceptions in callbacks from native code on OSX in SafeDeleteSslContext #49945
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
Conversation
Tagging subscribers to this area: @dotnet/ncl, @vcsjones Issue DetailsThis is alternative to #49657. Based on the feedback, I tried different approach and this is simple, scoped and effective - I did several hundred run (with #49573 clearing) on the whole test set and I did not see any problem. The two functions are called from native OS code and if we throw there is no good way to handle that. With this change, we simply return error code and that will eventually bubble up in OSX Pal. I think longer term we will need to change SslStream to avoid using SafeHandle after dispose to address #28171 and concerns from #47944. That will be separate change independent of the OSX specific handling. fixes #49600
|
src/libraries/System.Net.Security/src/System/Net/Security/Pal.OSX/SafeDeleteSslContext.cs
Show resolved
Hide resolved
This approach seems fine as long as we are never pooling the buffers here. It doesn't look like we are currently, but can we at least add a comment somewhere about this? |
It seems weird to me that we are managing input and output buffers on the SafeHandle itself here. Ideally we would just use the buffers on SslStream itself. But that's beyond the scope of this PR. And this is MacOS anyway so I'm not too worried about the perf/memory usage here. |
In case of Linux, this is handled inside input/output BIO. We write to it and then the data disappear into unmanaged space. |
@geoffkizer is this OK? |
Can we add a quick comment somewhere re this?
Aside from that it looks fine to me. |
Do you mean comment about not throwing in native callback or more specifically about the buffers? |
Specifically about the buffers. Just a comment along the lines of this: "We don't pool these buffers and we can't because there's a race between their use in the native read/write callbacks and being disposed when the SafeHandle is disposed. This race is benign currently, but if we were to pool the buffers we would have a potential use-after-free issue." |
This is alternative to #49657. Based on the feedback, I tried different approach and this is simple, scoped and effective - I did several hundred run (with #49573 clearing) on the whole test set and I did not see any problem. The two functions are called from native OS code and if we throw there is no good way to handle that. With this change, we simply return error code and that will eventually bubble up in OSX Pal.
I think longer term we will need to change SslStream to avoid using SafeHandle after dispose to address #28171 and concerns from #47944. That will be separate change independent of the OSX specific handling.
fixes #49600
fixes #43686
contributes to #49573