[fix] SSL session resumption failure due to BC classloader mismatch (… - #371
Open
Thiagott wants to merge 1 commit into
Open
[fix] SSL session resumption failure due to BC classloader mismatch (…#371Thiagott wants to merge 1 commit into
Thiagott wants to merge 1 commit into
Conversation
Thiagott
force-pushed
the
fix/ssl-session-resume-classloader-corruption
branch
from
August 13, 2026 20:57
882e33a to
ed18714
Compare
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.
Fixes #369.
What breaks and why
During
bundle installon a long-lived JVM, any Java gem with a post-install hook(e.g.
fast-rsa-engine,digest-crc,psych) can load BouncyCastle JARs via Mavenunder a new classloader. Once that happens there are two copies of BC in the same JVM,
and two bugs combine to make every subsequent HTTPS connection fatal.
Issue 1 —
BCSSLSupportProvSSLEngine.setBCSessionToResumethrowsIllegalArgumentExceptionbecause the storedBCExtendedSSLSessioncame from a different classloader than the current engine. Thatexception was uncaught and propagated as an
SSLError.Issue 2 —
SSLSocketWhen
setBCSessionToResumereturnedfalse, we calledengine.setEnableSessionCreation(false).If the stored session then couldn't be resumed for any reason, BC-JSSE threw instead of falling
back to a fresh handshake — which is the error users see:
OpenSSL::SSL::SSLError: No new session is allowed and no existing session can be resumed
Neither bug alone explains the full failure — both need to be fixed together.
The fix
BCSSLSupport.javaIllegalArgumentExceptionfromsetBCSessionToResumeand returnfalseso the caller falls back to a fresh handshakeSSLSocket.javasetEnableSessionCreation(false)— it was intended to enforce session reuse but makes any resumption failure unrecoverableTesting
Tested locally on macOS with JRuby 9.4.13.0 and a Gemfile that pulls in
fast-rsa-engine,digest-crc,ruby-maven-libs, andpsych— all gems that trigger JAR classloading viapost-install hooks.
Bundle complete! 101 gems now installed.✓