Skip to content

ssl: fix flaky test for SSLSocket#connect(timeout:) - #1167

Merged
rhenium merged 1 commit into
ruby:masterfrom
ko1:fix-flaky-test-connect-timeout
Nov 25, 2026
Merged

rhenium merged 1 commit into
ruby:masterfrom
ko1:fix-flaky-test-connect-timeout

Conversation

@ko1

@ko1 ko1 commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

NOTE: I don't understand the openssl and so on, but I asked Claude code to fix the following failure on CRuby's make test-all (on RISC-V SBC). I read its explanation and it seems making sense for me. Please use this PR if it is reasonable.

  1) Failure:
OpenSSL::TestSSL#test_connect_timeout [/tmp/ruby/src/trunk/test/openssl/utils.rb:264]:
exceptions on 1 threads:
#<Thread:0x0000003fbd9e45d8 /tmp/ruby/src/trunk/test/openssl/utils.rb:226 dead>:
/tmp/ruby/src/trunk/tool/lib/test/unit/assertions.rb:109:in ‘Test::Unit::Assertions#assert’: Expected :wait_readable (oid=4681996) to be the same as #<OpenSSL::SSL::SSLSocket:0x0000003fbd9e4790 (Test::Unit::AssertionFailedError)
 @context=
  #<OpenSSL::SSL::SSLContext:0x0000003fbd9e4768
   @verify_hostname=false,
   @verify_mode=0>,
 @eof=false,
 @io=#<TCPSocket:fd 14, AF_INET, 127.0.0.1, 34963>,
 @rbuffer=“”,
 @sync=true> (oid=9544).
	from /tmp/ruby/src/trunk/tool/lib/core_assertions.rb:850:in ‘Test::Unit::CoreAssertions#assert’
	from /tmp/ruby/src/trunk/tool/lib/test/unit/assertions.rb:286:in ‘Test::Unit::Assertions#assert_same’
	from /tmp/ruby/src/trunk/test/openssl/test_ssl.rb:201:in ‘block in OpenSSL::TestSSL#test_connect_timeout’
	from /tmp/ruby/src/trunk/test/openssl/utils.rb:229:in ‘block (4 levels) in OpenSSL::SSLTestCase#start_server_proc’

The following is the commit message from Claude code.


The server proc expected the second accept_nonblock, 0.2s after accept, to complete the handshake. That holds only if the client has sent its second flight (or closed) by then. On a slow machine the client with timeout: 0.1 could be stalled at that moment: its ClientHello or its second flight was not yet sent and the socket was still open, so accept_nonblock returned :wait_readable and the assertion failed (seen on trunk@lpi4a, riscv64).

Just making the server accept blocking is not enough: the stalled client then finds the handshake completed when it resumes, and connect returns successfully past its deadline because the IO is already readable.

Split the test into two connections with separate servers:

  • a server that answers ClientHello and never finishes the handshake, so connect(timeout: 0.1) must raise;
  • a server that delays both round trips and then blocks in accept, so connect(timeout: 1) succeeds after at least 0.2s.

The server proc expected the second accept_nonblock, 0.2s after accept,
to complete the handshake. That holds only if the client has sent its
second flight (or closed) by then. On a slow machine the client with
`timeout: 0.1` could be stalled at that moment: its ClientHello or its
second flight was not yet sent and the socket was still open, so
accept_nonblock returned :wait_readable and the assertion failed
(seen on trunk@lpi4a, riscv64).

Just making the server accept blocking is not enough: the stalled client
then finds the handshake completed when it resumes, and connect returns
successfully past its deadline because the IO is already readable.

Split the test into two connections with separate servers:

- a server that answers ClientHello and never finishes the handshake,
  so connect(timeout: 0.1) must raise;
- a server that delays both round trips and then blocks in accept, so
  connect(timeout: 1) succeeds after at least 0.2s.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@rhenium rhenium left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the catch! The current test seems problematic because there's no guarantee that the server's first accept_nonblock happens after the client has sent a ClientHello.

@rhenium
rhenium merged commit 1ea17b5 into ruby:master Nov 25, 2026
49 checks passed
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.

2 participants