-
Notifications
You must be signed in to change notification settings - Fork 271
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
Fix thread safety issue with encoding tables #515
Conversation
07511f2
to
b54a4bc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks much simpler, thank you!
lib/addressable/uri.rb
Outdated
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('|') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 (|%
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hum, I think you are right, but it's weird because I didn't change that 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah nevermind, I get it now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be good now.
Fix: sporkmonger#514 Fix: oracle/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
What do we think about the ruby-head failure? |
It is. |
It currently crashes: sporkmonger#515 (comment)
It currently crashes: #515 (comment)
Fix: #514
Fix: oracle/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.