Repository navigation
Leave the shared stream BIO method allocated at exit - #109
Merged
Merged
Conversation
Every SSLStream's BIOs use one BIO method, created in `__init__`. It had a finalizer, and Julia runs every finalizer at exit while other threads keep running: a stream created or freed on another thread after that finalizer ran called BIO_new/BIO_free with a freed (then NULL) method and crashed the process (12 of 20 exits crashed in a stress run with three threads making streams; 0 of 20 with this change). The method now lives as long as the process, like OpenSSL's own static methods. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #109 +/- ##
==========================================
- Coverage 83.07% 83.05% -0.02%
==========================================
Files 2 2
Lines 1341 1340 -1
==========================================
- Hits 1114 1113 -1
Misses 227 227 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Every
SSLStream's two BIOs use one BIO method,BIO_STREAM_METHOD, created in__init__. It had a finalizer (BIO_meth_free). Julia runs every finalizer at exit, also for live objects, while other threads keep running, so a stream created (BIO_new) or freed (SSL_free→BIO_free, which calls the method'sdestroy) on another thread after that finalizer ran used a freed method, and afterfreeset the pointer toC_NULL, a NULL one: a segfault inBIO_new_exat exit.The method now has no finalizer and lives as long as the process, like OpenSSL's own static
BIO_s_*methods. Only__init__calls this constructor.Verification
StreamMethodOutlivesFinalizers: a subprocess runs the method's finalizer (as exit would), then makes a stream. Onmainit segfaults inBIO_new_ex(the test fails); with the fix it passes.closedoes) in a loop while the main thread callsexit(0),-t 4.main: 12 of 20 runs crashed (SIGSEGV inBIO_new_ex); this branch: 0 of 20.-t 4: passes.Self-review
BIOMethod(::String)is only called from__init__; theBIOMethod(::Ptr)constructor (OpenSSL's static methods) never had a finalizer. A caller that makes its ownBIOMethod("name")now has tofreeit.SSL_free→BIO_free→ the method'sdestroy) now always see a live method. The method's memory is reclaimed by the process exit; OpenSSL's own atexit cleanup does not touch it.🤖 Generated with Claude Code