Skip to content

Restore message logging and clear write state on exceptional exits - #71

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

Restore message logging and clear write state on exceptional exits#71
OskarEichler wants to merge 1 commit into
ruby:masterfrom
OskarEichler:codex/cleanup-buffered-io

Conversation

@OskarEichler

Copy link
Copy Markdown

Summary

Restore temporarily disabled message logging and clear temporary write buffers/counters with ensure when reads, sources, writes or user blocks exit exceptionally. Do not finish or send the message terminator on failure.

Reproduction

require 'net/protocol'
require 'stringio'
debug, wire = StringIO.new, StringIO.new
io = Net::InternetMessageIO.new(wire, debug_output: debug)
begin
  io.write_message_by_block { |w| w << 'partial'; raise 'stop' }
rescue RuntimeError
end
p io.debug_output.equal?(debug)         # before: false; after: true
p io.instance_variable_get(:@wbuf)      # before: "partial"; after: nil
p io.instance_variable_get(:@written_bytes) # before: 0; after: nil
p wire.string                          # empty before and after

Focused checks cover reader EOF and block exceptions, nonlocal read exits, failing enumerable sources and IO writes, nonlocal writer breaks, successful empty/dot-stuffed/unterminated messages, exact byte counts and ordinary BufferedIO write failure. Original exceptions/return values are preserved.

Verification

Compatibility and limitations

No signature changes or successful wire-format changes. Logging is restored after failure, and failed calls no longer retain partial message data/counters. This cleanup does not make a partially failed protocol exchange safe to resume; callers must retain their existing connection-disposal behavior.

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