diff --git a/ext/openssl/ossl_ssl.c b/ext/openssl/ossl_ssl.c index b29e45f84..4fdb7b11b 100644 --- a/ext/openssl/ossl_ssl.c +++ b/ext/openssl/ossl_ssl.c @@ -1894,6 +1894,7 @@ ossl_start_ssl(VALUE self, int (*func)(SSL *), const char *funcname) cb_state = rb_attr_get(self, ID_callback_state); if (!NIL_P(cb_state)) { + rb_ivar_set(self, ID_callback_state, Qnil); /* must cleanup OpenSSL error stack before re-raising */ ossl_clear_error(); rb_jump_tag(NUM2INT(cb_state)); diff --git a/test/openssl/test_ssl.rb b/test/openssl/test_ssl.rb index 3a548e36f..2358e69b6 100644 --- a/test/openssl/test_ssl.rb +++ b/test/openssl/test_ssl.rb @@ -1213,6 +1213,7 @@ def test_servername_cb_exception sctx.servername_cb = lambda { |args| raise RuntimeError, "foo" } ssl = OpenSSL::SSL::SSLSocket.new(sock, sctx) assert_raise_with_message(RuntimeError, "foo") { ssl.accept } + assert_raise(OpenSSL::SSL::SSLError) { ssl.syswrite("abc") } end start_server_proc(server_proc) do |port| sock = TCPSocket.new("127.0.0.1", port)