Skip to content

Wait for readability when an SSL write requests it - #70

Open
OskarEichler wants to merge 1 commit into
ruby:masterfrom
OskarEichler:codex/readiness-buffered-io
Open

Wait for readability when an SSL write requests it#70
OskarEichler wants to merge 1 commit into
ruby:masterfrom
OskarEichler:codex/readiness-buffered-io

Conversation

@OskarEichler

Copy link
Copy Markdown

Summary

Handle :wait_readable from write_nonblock(exception: false), wait with write_timeout, and raise Net::WriteTimeout if readiness is not reached. The current case statement retries that result immediately without any wait or timeout.

Reproduction

OpenSSL::Buffering#write_nonblock documents both readiness directions, including :wait_readable with exception: false.

require 'net/protocol'
writer = Object.new
writes = waits = 0
writer.define_singleton_method(:to_io) { self }
writer.define_singleton_method(:wait_readable) { |timeout| waits += 1; true }
writer.define_singleton_method(:write_nonblock) do |str, exception:|
  writes += 1
  writes == 1 ? :wait_readable : str.bytesize
end
p Net::BufferedIO.new(writer, write_timeout: 0.125).write('abc') # 3
p waits # before: 0; after: 1

Bounded deterministic IO doubles also cover timeout without a retry, partial writes, multiple strings, alternating readiness directions, preserved output and the timeout's IO reference.

Verification

Compatibility and limitations

No signature changes. A write waiting for read readiness now honors write_timeout instead of busy-retrying. Validation exercises the documented IO contract; it does not claim a reproduced live TLS renegotiation or cross-platform TLS test.

The patch also applies to installed release 0.3.0, whose runtime file matches the reviewed master. Gem version, dependencies and Ruby >= 2.6 requirement stay unchanged. Only macOS/Ruby 4.0.6 was run locally; other Ruby/OS combinations require upstream CI. No production traffic or external service was used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant