Skip to content

ssl: clear error queue before raising SystemCallError - #1115

Merged
rhenium merged 1 commit into
ruby:masterfrom
rhenium:ky/ssl-handshake-clear-error-on-syserr
Sep 24, 2026
Merged

rhenium merged 1 commit into
ruby:masterfrom
rhenium:ky/ssl-handshake-clear-error-on-syserr

Conversation

@rhenium

@rhenium rhenium commented Sep 24, 2026

Copy link
Copy Markdown
Member

Clear the OpenSSL error queue when an OpenSSL function fails with SSL_ERROR_SYSCALL. ruby/openssl methods are expected not to leave stale entries in the error queue.

While this no longer appears to happen with OpenSSL >= 3.0, LibreSSL and older versions of OpenSSL may generate an ERR_LIB_SYS entry in the error queue when the underlying socket fails with an errno. This entry must be cleared before another OpenSSL function is called, otherwise SSL_get_error() for that call may return an incorrect result.

Fixes #1114

Clear the OpenSSL error queue when an OpenSSL function fails with
SSL_ERROR_SYSCALL. ruby/openssl methods are expected not to leave stale
entries in the error queue.

While this no longer appears to happen with OpenSSL >= 3.0, LibreSSL
and older versions of OpenSSL may generate an ERR_LIB_SYS entry in the
error queue when the underlying socket fails with an errno. This entry
must be cleared before another OpenSSL function is called, otherwise
SSL_get_error() for that call may return an incorrect result.

Fixes ruby#1114
@rhenium
rhenium merged commit ed948ea into ruby:master Sep 24, 2026
48 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.

1 participant