Issue #797: Handle multi-byte body in Net::HTTP on ruby 2.6.0 #814
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.
#797
Ruby 2.6.0 has a bug where large payloads for
Net::HTTP::Post
are silently truncated. It turns out that this is caused by incorrectly calculating the byte length for payloads with multi-byte characters, and therefore the bug is limited to requests that do have multi-byte characters. Also, the error involves the length returned byIO#io.write_nonblock
.Several solutions have been considered. Splitting payloads in advance cannot be guaranteed to work in all cases because the behavior of
IO#io.write_nonblock
is platform dependent. A threshold length that works most of the time can't be known to work in all cases. Monkey patchingNet::BufferedIO#write0
would work, however the solution in this PR does not require patching core Ruby.In this PR, only if the current Ruby is 2.6.0 and the current payload is found to contain multi-byte characters, we unpack the string and repack as single bytes characters. This avoids the bug in Ruby, and is handled correctly on the receiving end (Rollbar notifier API.)