Skip to content

Commit

Permalink
Report CLOSED_CONNECTION for SSL_ERROR_ZERO_RETURN
Browse files Browse the repository at this point in the history
If a server closes the SSL connection cleanly (SSL_shutdown) as we
attempt a read or write (ie. a clean SSL shutdown but dirty MySQL
shutdown) we will get SSL_ERROR_ZERO_RETURN as the return code.

Previously we would have reported this as:

    Trilogy::SSLError: trilogy_query_recv: SSL Error: (null)

Now it will be reported as:

    Trilogy::EOFError: trilogy_query_recv: TRILOGY_CLOSED_CONNECTION

On older versions (< 2.5.0) we may also have reported this as
TRILOGY_CLOSED_CONNECTION.

Co-authored-by: Brendan Dougherty <b.w.dougherty@gmail.com>
  • Loading branch information
jhawthorn and brendar committed Oct 17, 2023
1 parent d69ae30 commit 4eb7a82
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,9 @@ static ssize_t ssl_io_return(struct trilogy_sock *sock, ssize_t ret)
int rc = SSL_get_error(sock->ssl, (int)ret);
if (rc == SSL_ERROR_WANT_WRITE || rc == SSL_ERROR_WANT_READ) {
return (ssize_t)TRILOGY_AGAIN;
} else if (rc == SSL_ERROR_ZERO_RETURN) {
// Server has closed the connection for writing by sending the close_notify alert
return (ssize_t)TRILOGY_CLOSED_CONNECTION;
} else if (rc == SSL_ERROR_SYSCALL && !ERR_peek_error()) {
if (errno == 0) {
// On OpenSSL <= 1.1.1, SSL_ERROR_SYSCALL with an errno value
Expand Down

0 comments on commit 4eb7a82

Please sign in to comment.