-
Notifications
You must be signed in to change notification settings - Fork 5.1k
make sure OpenSSL is initialized before Tls13Supported code runs #62037
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -191,8 +191,14 @@ internal static byte[] ConvertAlpnProtocolListToByteArray(List<SslApplicationPro | |
} | ||
|
||
[GeneratedDllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_Tls13Supported")] | ||
private static partial int Tls13SupportedImpl(); | ||
internal static readonly bool Tls13Supported = Tls13SupportedImpl() != 0; | ||
private static partial int Tls13SupportedNative(); | ||
internal static readonly bool Tls13Supported = Tls13SupportedImpl(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rather than all this work, if the readonly-ness is still important, I'd suggest just moving the static field to a different type (just somewhere in System.Net.Security instead of in Common/src/Interop) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't have any benchmarks. But it seems like doing something once is better than possibly insure some repeatedly. |
||
|
||
internal static bool Tls13SupportedImpl() | ||
{ | ||
EsureInitialized(); | ||
return Tls13SupportedNative() != 0; | ||
} | ||
|
||
internal static SafeSharedX509NameStackHandle SslGetClientCAList(SafeSslHandle ssl) | ||
{ | ||
|
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.
None of this locking is necessary, or really even useful. It can run in parallel across (today) 4 different assemblies. Even after I'm done collapsing things it'll still be two. So the called code is (supposed to be) defensive against concurrency.
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 know it can run. But that will make it visible to
strace
or run with LD_DEBUG, would it not?What I'm trying to argue is that we can do unnecessary file system operation and system calls.
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.
The library load will only ever happen once, the P/Invoke into EnsureLibSslInitialized will only happen once per assembly (cctor guarantee), and the cascaded EnsureOpenSslInitialized will only happen once per assembly. If you do the change as currently structured but remove the locking then there might be two calls to EnsureLibSslInitialized (one from the cctor, one from the extra explicit call).
Restructuring things to move the field off this class will keep things simple looking while staying with the current initialize-count. Even just making a nested type will fix it... e.g.
Interop.Ssl.Tls13Supported
=>Interop.Ssl.Capabilities.Tls13Supported
.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 makes sense to me.