-
Notifications
You must be signed in to change notification settings - Fork 141
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
Weird crash under Linux when trying to deallocate SSLContext (and also linking with BoringSSL) #16
Comments
Looking... |
I think I know what's wrong... stay tuned |
I'll chase this this morning. I suspect this is fundamentally related to having two copies of |
@Lukasa thanks... as discussed offline my idea did turn out to be wrong :( |
That's my hunch as well. Thank you both for looking into this, especially given that this linking two copies of P.S.: @normanmaurer, what was your idea? :-) |
Yeah, so my hunch is looking likely. Here's the backtrace:
In particular, note that ssl_cert_free is pretty clearly in the binary (its address is very close to You can see where this problem comes from when I set some breakpoints. In particular, if I run
Note that Unfortunately there's an extremely limited amount we can do here because of the way BoringSSL is being used by As a further concern, I should note that This is a problem we have encountered before. The original design for this module called for using BoringSSL directly, and we shelved that plan temporarily because of the discovery that I'm actively investigating other options for supporting this model. One option is potentially to enhance SwiftPM to let us mix Swift and C in the same module, and then compile the C code with Another option is to try to excise the OpenSSL dependency from In the short term, my TL;DR is that BoringSSL is entirely incompatible with Swift on Linux. I recommend investigating whether the |
Under Linux, `libFoundation.so` already links with the system OpenSSL; so we need to use that one. Using two `libssl`-style libraries in the same binary can cause all sorts of mayhem; see apple/swift-nio-ssl#16 (comment) for details.
Under Linux, `libFoundation.so` already links with the system OpenSSL; so we need to use that one. Using two `libssl`-style libraries in the same binary can cause all sorts of mayhem; see apple/swift-nio-ssl#16 (comment) for details.
@Lukasa thank you for your work investigating this! I have filed grpc/grpc-swift#238 that migrates SwiftGRPC to |
Under Linux, `libFoundation.so` already links with the system OpenSSL; so we need to use that one. Using two `libssl`-style libraries in the same binary can cause all sorts of mayhem; see apple/swift-nio-ssl#16 (comment) for details.
Under Linux, `libFoundation.so` already links with the system OpenSSL; so we need to use that one. Using two `libssl`-style libraries in the same binary can cause all sorts of mayhem; see apple/swift-nio-ssl#16 (comment) for details.
I'm using SwiftNIO and gRPC in one binary, which means that I need to link with both
openssl
(for SwiftNIO) andBoringSSL
(for gRPC). (I know, linking with two variants ofopenssl
at the same time is a terrible idea, but I can't avoid that right now :-/)Unfortunately, since 8e0aa76, I am encountering crashes under Linux when any
SSLContext
instance is deallocated (see https://github.com/MrMage/openssl-crash-test/blob/master/Sources/openssl-crash-test/main.swift for example code). I have also confirmed that this works when removing theSSL_CTX_ctrl(ctx, SSL_CTRL_MODE, SSL_MODE_RELEASE_BUFFERS | SSL_MODE_AUTO_RETRY, nil)
line as in master...MrMage:disable-release-buffers, and my service indeed used to work fine. Setting only eitherSSL_MODE_RELEASE_BUFFERS
orSSL_MODE_AUTO_RETRY
both still crash.Unfortunately, I was not yet able to extract a usable stack trace — I just get a "Segmentation Fault" error. Weirdly enough, all other
SSL_CTX_ctrl
calls cause no crashes later on.I am aware that this is a very fringe case, but any ideas you might have would be appreciated.
FYI, I have prepared a sample repository at https://github.com/MrMage/openssl-crash-test — simply clone it and run
docker build --no-cache .
(requires Docker installed of course). This will compile the sample project and run it right away, at which point you can reproduce the crash.The text was updated successfully, but these errors were encountered: