Skip to content

Commit

Permalink
Merge pull request #706 from jaymzjulian/fix-large-buffered-write-reg…
Browse files Browse the repository at this point in the history
…ression

Fix regression in do_write(s) causing significant performance issues when using large (>10meg) writes
  • Loading branch information
rhenium committed Mar 21, 2024
2 parents ccc1594 + d4389b4 commit 1bb0ce2
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions lib/openssl/buffering.rb
Expand Up @@ -348,13 +348,18 @@ def do_write(s)
@wbuffer << s
@wbuffer.force_encoding(Encoding::BINARY)
@sync ||= false
if @sync or @wbuffer.size > BLOCK_SIZE
until @wbuffer.empty?
begin
nwrote = syswrite(@wbuffer)
rescue Errno::EAGAIN
retry
buffer_size = @wbuffer.size
if @sync or buffer_size > BLOCK_SIZE
nwrote = 0
begin
while nwrote < buffer_size do
begin
nwrote += syswrite(@wbuffer[nwrote, buffer_size - nwrote])
rescue Errno::EAGAIN
retry
end
end
ensure
@wbuffer[0, nwrote] = ""
end
end
Expand Down

0 comments on commit 1bb0ce2

Please sign in to comment.