diff -ru mariadb-connector-c-3.3.3-src/include/ma_pvio.h mariadb-connector-c-3.3.3-src-minfix/include/ma_pvio.h --- mariadb-connector-c-3.3.3-src/include/ma_pvio.h 2022-11-07 00:09:29.000000000 -0800 +++ mariadb-connector-c-3.3.3-src-minfix/include/ma_pvio.h 2022-12-21 18:14:02.409869502 -0800 @@ -36,6 +36,8 @@ #define IS_MYSQL_ASYNC_ACTIVE(a) \ (IS_MYSQL_ASYNC(a)&& (a)->options.extension->async_context->active) +#define MATCH_PVIO_SYNC_OR_ASYNC(a) !IS_PVIO_ASYNC(a) + enum enum_pvio_timeout { PVIO_CONNECT_TIMEOUT= 0, PVIO_READ_TIMEOUT, diff -ru mariadb-connector-c-3.3.3-src/libmariadb/ma_net.c mariadb-connector-c-3.3.3-src-minfix/libmariadb/ma_net.c --- mariadb-connector-c-3.3.3-src/libmariadb/ma_net.c 2022-11-07 00:09:29.000000000 -0800 +++ mariadb-connector-c-3.3.3-src-minfix/libmariadb/ma_net.c 2022-12-21 18:14:02.409869502 -0800 @@ -103,7 +103,7 @@ if (pvio != 0) /* If real connection */ { ma_pvio_get_handle(pvio, &net->fd); - ma_pvio_blocking(pvio, 1, 0); + ma_pvio_blocking(pvio, MATCH_PVIO_SYNC_OR_ASYNC(pvio), 0); ma_pvio_fast_send(pvio); } return 0; diff -ru mariadb-connector-c-3.3.3-src/libmariadb/ma_pvio.c mariadb-connector-c-3.3.3-src-minfix/libmariadb/ma_pvio.c --- mariadb-connector-c-3.3.3-src/libmariadb/ma_pvio.c 2022-11-07 00:09:29.000000000 -0800 +++ mariadb-connector-c-3.3.3-src-minfix/libmariadb/ma_pvio.c 2022-12-22 22:40:20.956817274 -0800 @@ -199,7 +199,7 @@ if (res >= 0 || IS_BLOCKING_ERROR()) return res; b->events_to_wait_for= MYSQL_WAIT_READ; - if (timeout >= 0) + if (timeout > 0) { b->events_to_wait_for|= MYSQL_WAIT_TIMEOUT; b->timeout_value= timeout; @@ -325,7 +325,7 @@ if (res >= 0 || IS_BLOCKING_ERROR()) return res; b->events_to_wait_for= MYSQL_WAIT_WRITE; - if (timeout >= 0) + if (timeout > 0) { b->events_to_wait_for|= MYSQL_WAIT_TIMEOUT; b->timeout_value= timeout; @@ -402,9 +402,11 @@ /* {{{ void ma_pvio_close */ void ma_pvio_close(MARIADB_PVIO *pvio) { + MYSQL *mysql; /* free internal structures and close connection */ if (pvio) { + mysql = pvio->mysql; #ifdef HAVE_TLS if (pvio->ctls) { @@ -418,6 +420,10 @@ if (pvio->cache) free(pvio->cache); + /* if there is an ongoing async operation */ + if (mysql->options.extension && mysql->options.extension->async_context && mysql->options.extension->async_context->pvio) + mysql->options.extension->async_context->pvio = 0; /* clear pvio about to be freed */ + free(pvio); } } @@ -450,7 +456,7 @@ break; } - if (timeout >= 0) + if (timeout > 0) { b->events_to_wait_for |= MYSQL_WAIT_TIMEOUT; b->timeout_value= timeout; diff -ru mariadb-connector-c-3.3.3-src/libmariadb/secure/openssl.c mariadb-connector-c-3.3.3-src-minfix/libmariadb/secure/openssl.c --- mariadb-connector-c-3.3.3-src/libmariadb/secure/openssl.c 2022-11-07 00:09:29.000000000 -0800 +++ mariadb-connector-c-3.3.3-src-minfix/libmariadb/secure/openssl.c 2022-12-21 18:14:02.410869493 -0800 @@ -456,6 +456,8 @@ return NULL; } +extern int ma_pvio_wait_io_or_timeout(MARIADB_PVIO *pvio, my_bool is_read, int timeout); + my_bool ma_tls_connect(MARIADB_TLS *ctls) { SSL *ssl = (SSL *)ctls->ssl; @@ -490,11 +492,11 @@ { switch((SSL_get_error(ssl, rc))) { case SSL_ERROR_WANT_READ: - if (pvio->methods->wait_io_or_timeout(pvio, TRUE, mysql->options.connect_timeout) < 1) + if (ma_pvio_wait_io_or_timeout(pvio, TRUE, pvio->timeout[PVIO_CONNECT_TIMEOUT]) < 1) /* handle non-blocking read */ try_connect= 0; break; case SSL_ERROR_WANT_WRITE: - if (pvio->methods->wait_io_or_timeout(pvio, TRUE, mysql->options.connect_timeout) < 1) + if (ma_pvio_wait_io_or_timeout(pvio, FALSE, pvio->timeout[PVIO_CONNECT_TIMEOUT]) < 1) /* handle non-blocking write */ try_connect= 0; break; default: @@ -530,7 +532,7 @@ } static my_bool -ma_tls_async_check_result(int res, struct mysql_async_context *b, SSL *ssl) +ma_tls_async_check_result(int res, struct mysql_async_context *b, SSL *ssl, int timeout) { int ssl_err; b->events_to_wait_for= 0; @@ -543,6 +545,11 @@ b->events_to_wait_for|= MYSQL_WAIT_WRITE; else return 1; + if (timeout > 0) + { + b->events_to_wait_for|= MYSQL_WAIT_TIMEOUT; + b->timeout_value= timeout; + } if (b->suspend_resume_hook) (*b->suspend_resume_hook)(TRUE, b->suspend_resume_hook_user_data); my_context_yield(&b->async_context); @@ -557,13 +564,16 @@ { int res; struct mysql_async_context *b= pvio->mysql->options.extension->async_context; + int timeout= pvio->timeout[PVIO_READ_TIMEOUT]; MARIADB_TLS *ctls= pvio->ctls; for (;;) { res= SSL_read((SSL *)ctls->ssl, (void *)buffer, (int)length); - if (ma_tls_async_check_result(res, b, (SSL *)ctls->ssl)) + if (ma_tls_async_check_result(res, b, (SSL *)ctls->ssl, timeout)) return res; + if (b->events_occurred & MYSQL_WAIT_TIMEOUT) + return -1; } } @@ -573,13 +583,16 @@ { int res; struct mysql_async_context *b= pvio->mysql->options.extension->async_context; + int timeout= pvio->timeout[PVIO_WRITE_TIMEOUT]; MARIADB_TLS *ctls= pvio->ctls; for (;;) { res= SSL_write((SSL *)ctls->ssl, (void *)buffer, (int)length); - if (ma_tls_async_check_result(res, b, (SSL *)ctls->ssl)) + if (ma_tls_async_check_result(res, b, (SSL *)ctls->ssl, timeout)) return res; + if (b->events_occurred & MYSQL_WAIT_TIMEOUT) + return -1; } } diff -ru mariadb-connector-c-3.3.3-src/plugins/pvio/pvio_socket.c mariadb-connector-c-3.3.3-src-minfix/plugins/pvio/pvio_socket.c --- mariadb-connector-c-3.3.3-src/plugins/pvio/pvio_socket.c 2022-11-07 00:09:29.000000000 -0800 +++ mariadb-connector-c-3.3.3-src-minfix/plugins/pvio/pvio_socket.c 2022-12-21 18:14:02.411869484 -0800 @@ -832,7 +832,7 @@ ER(CR_CONNECTION_ERROR), cinfo->unix_socket, socket_errno); goto error; } - if (pvio_socket_blocking(pvio, 1, 0) == SOCKET_ERROR) + if (pvio_socket_blocking(pvio, MATCH_PVIO_SYNC_OR_ASYNC(pvio), 0) == SOCKET_ERROR) { goto error; } @@ -992,7 +992,7 @@ #endif goto error; } - if (pvio_socket_blocking(pvio, 1, 0) == SOCKET_ERROR) + if (pvio_socket_blocking(pvio, MATCH_PVIO_SYNC_OR_ASYNC(pvio), 0) == SOCKET_ERROR) goto error; } /* apply timeouts */