From ad02bb94b9a8e3718608c019c14a191df0329a72 Mon Sep 17 00:00:00 2001 From: Alan Wu Date: Wed, 13 Oct 2021 15:55:24 -0400 Subject: [PATCH] Flaky repro for compaction issue ossl_ssl_initialize() sets a Ruby reference on an OpenSSL handle and it's retrived later for calling callbacks such as session_new_cb. There is nothing marking the reference that lives on the SSL handle, so the reference could move and cause crashes later when the stale reference is used. On my machine I get a crash with this change running the following tests in a loop: bundle exec rake test TEST=test/openssl/test_ssl_session.rb TESTOPTS='-n/cb/' --- test/openssl/test_ssl_session.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/test/openssl/test_ssl_session.rb b/test/openssl/test_ssl_session.rb index a98efdae2..5b6eda4f4 100644 --- a/test/openssl/test_ssl_session.rb +++ b/test/openssl/test_ssl_session.rb @@ -387,7 +387,12 @@ def test_dup def server_connect_with_session(port, ctx = nil, sess = nil) sock = TCPSocket.new("127.0.0.1", port) ctx ||= OpenSSL::SSL::SSLContext.new - ssl = OpenSSL::SSL::SSLSocket.new(sock, ctx) + @ssl = OpenSSL::SSL::SSLSocket.new(sock, ctx) + itself + if GC.respond_to?(:verify_compaction_references) + GC.verify_compaction_references(double_heap: true, toward: :empty) + end + ssl = @ssl ssl.session = sess if sess ssl.sync_close = true ssl.connect