Fix thread safety issue with encoding tables#515
Merged
dentarg merged 2 commits intosporkmonger:mainfrom Jul 31, 2023
Merged
Conversation
07511f2 to
b54a4bc
Compare
eregon
reviewed
Jul 31, 2023
Contributor
eregon
left a comment
There was a problem hiding this comment.
This looks much simpler, thank you!
| end.join('|')})" | ||
| bytes = leave_encoded.bytes | ||
| leave_encoded_downcase = bytes.map { |b| SEQUENCE_ENCODING_TABLE[b] }.join('|') | ||
| leave_encoded_upcase = bytes.map { |b| SEQUENCE_UPCASED_PERCENT_ENCODING_TABLE[b] }.join('|') |
Contributor
There was a problem hiding this comment.
SEQUENCE_UPCASED_PERCENT_ENCODING_TABLE has extra %:
SEQUENCE_ENCODING_TABLE[
> format("%02x", 45)
=> "2d"
SEQUENCE_UPCASED_PERCENT_ENCODING_TABLE
> format("%%%02X", 45)
=> "%2D"
So it should be without the % because that's already present outside (|%)
Contributor
Author
There was a problem hiding this comment.
Hum, I think you are right, but it's weird because I didn't change that 🤔
Contributor
Author
There was a problem hiding this comment.
Ah nevermind, I get it now.
Contributor
Author
There was a problem hiding this comment.
Should be good now.
Fix: sporkmonger#514 Fix: truffleruby/truffleruby#3166 These hashes lazily memoize percent encoded characters, this is an issue on GVL-less Ruby implementations as it can cause concurrent access. But these are actually quite wastful as the key is always a single byte so rather than use string keys are lazily memoize these, we can precompute two static arrays of 255 elements once and for all.
b54a4bc to
203eafd
Compare
Collaborator
|
What do we think about the ruby-head failure? |
Contributor
Author
It is. |
dentarg
approved these changes
Jul 31, 2023
dentarg
added a commit
to dentarg/addressable
that referenced
this pull request
Jul 31, 2023
It currently crashes: sporkmonger#515 (comment)
Merged
dentarg
added a commit
that referenced
this pull request
Jul 31, 2023
It currently crashes: #515 (comment)
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.
Fix: #514
Fix: truffleruby/truffleruby#3166
These hashes lazily memoize percent encoded characters, this is an issue on GVL-less Ruby implementations as it can cause concurrent access.
But these are actually quite wasteful as the key is always a single byte so rather than use string keys are lazily memoize these, we can precompute two static arrays of 255 elements once and for all.
@eregon @dentarg
NB: I'm not a big addressable user, so I mostly relied on the test suite, hopefully my assertions are correct.