Repository navigation
Conversation
Under the M:N thread scheduler, a Ruby thread in a non-main Ractor may
be resumed on a different native thread after rb_thread_call_without_gvl()
returns. The OpenSSL error queue is thread-local, so errors pushed by
the function without the GVL are left on the previous native thread:
the exception loses its reason, and the stray errors appear in an
unrelated exception raised later on that native thread.
8.times.map {
Ractor.new {
4.times.map {
Thread.new {
2000.times.map do
OpenSSL::KDF.pbkdf2_hmac("", salt: "", iterations: 0, length: 1, hash: "sha256")
rescue OpenSSL::KDF::KDFError => e
e.message
end.uniq
}
}.flat_map(&:value).uniq
}
}.flat_map(&:value).uniq
#=> ["PKCS5_PBKDF2_HMAC: invalid iteration count", "PKCS5_PBKDF2_HMAC"]
Save the error queue at the end of the function and restore it after
the GVL is reacquired, using OSSL_ERR_STATE (OpenSSL 3.2+).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Member
|
I hadn't thought about this. Thanks for catching it!
I think it would also be acceptable for these methods to clear the queue, since I expect they fail only because of invalid argument values. I suspect this might not be the only place ruby/openssl breaks if the native thread changes. In particular, some |
This branch has not been deployed
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.
Under the M:N thread scheduler, a Ruby thread in a non-main Ractor may be resumed on a different native thread after rb_thread_call_without_gvl() returns. The OpenSSL error queue is thread-local, so errors pushed by the function without the GVL are left on the previous native thread: the exception loses its reason, and the stray errors appear in an unrelated exception raised later on that native thread.
Save the error queue at the end of the function and restore it after the GVL is reacquired, using OSSL_ERR_STATE (OpenSSL 3.2+).
What do you think? @ko1 @rhenium