Skip to content

Reject nested SMTP starts before entering session cleanup - #100

Open
OskarEichler wants to merge 2 commits into
ruby:masterfrom
OskarEichler:codex/nested-smtp
Open

Reject nested SMTP starts before entering session cleanup#100
OskarEichler wants to merge 2 commits into
ruby:masterfrom
OskarEichler:codex/nested-smtp

Conversation

@OskarEichler

Copy link
Copy Markdown

Summary

Reject an already-started SMTP session before entering block-form start cleanup. Previously the IOError was raised by do_start inside the ensure scope, so an unsuccessful nested start sent QUIT and closed the caller's active session.

Reproduction

require 'net/smtp'
smtp = Net::SMTP.new('example.invalid', starttls: false)
# Isolate cleanup without an external SMTP server.
socket = Object.new
def socket.closed? = true
def socket.close = nil
smtp.instance_variable_set(:@socket, socket)
smtp.instance_variable_set(:@started, true)
begin
  smtp.start { raise 'must not yield' }
rescue IOError => e
  p e.message
end
p smtp.started? # before: false; after: true
p smtp.instance_variable_get(:@socket).equal?(socket) # false -> true

Verification

  • 18 focused checks include bounded real localhost sessions: both block and non-block repeated starts raise the same IOError, never yield, retain the original connection, and allow an actual RSET afterward. Normal block return/cleanup is retained. Baseline: five failed expectations; patched: zero.
  • Existing rake test: 95 tests, 170 assertions, zero failures/errors, on baseline and this isolated branch, Ruby 4.0.6 via rbenv. Existing local TLS cases are included.
  • Supplemental RuboCop Lint has the same six existing findings; Ruby syntax and git diff --check pass. No new/modified repository tests, dependencies or workflow settings.
  • Independent branch based on c2e9102e1f199a5a10e5261a776d752e64cc130f; runtime matches released 0.5.1. External focused checks were used under the consumer repository's no-new-tests policy.

Compatibility and limits

No public signature or exception-class/message change. An unsuccessful nested start no longer closes the already-active session. Argument-count validation retains precedence. Related open #86 proposes a broader quit/disconnect API; this patch adds no such API. Other Ruby/OS runtimes were not run locally. No production or external SMTP delivery was used. Maintainer CI status is separate from these local checks.

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