From: Vsevolod Stakhov Date: Tue, 31 Mar 2020 11:19:59 +0000 (+0100) Subject: [Minor] Check socket error when reusing redis pool connections X-Git-Tag: 2.5~3 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=fad056e59bea821222f9f4123550dd424e0836f5;p=thirdparty%2Frspamd.git [Minor] Check socket error when reusing redis pool connections --- diff --git a/src/libserver/http/http_context.c b/src/libserver/http/http_context.c index 761760b5ae..c6119eeca7 100644 --- a/src/libserver/http/http_context.c +++ b/src/libserver/http/http_context.c @@ -423,7 +423,7 @@ rspamd_http_context_check_keepalive (struct rspamd_http_context *ctx, conn = cbd->conn; g_free (cbd); - if (getsockopt(conn->fd, SOL_SOCKET, SO_ERROR, (void *) &err, &len) == -1) { + if (getsockopt (conn->fd, SOL_SOCKET, SO_ERROR, (void *) &err, &len) == -1) { err = errno; } diff --git a/src/libserver/redis_pool.c b/src/libserver/redis_pool.c index 57fc734f9a..4d1a186762 100644 --- a/src/libserver/redis_pool.c +++ b/src/libserver/redis_pool.c @@ -401,11 +401,30 @@ rspamd_redis_pool_connect (struct rspamd_redis_pool *pool, g_assert (conn->state != RSPAMD_REDIS_POOL_CONN_ACTIVE); if (conn->ctx->err == REDIS_OK) { - ev_timer_stop (elt->pool->event_loop, &conn->timeout); - conn->state = RSPAMD_REDIS_POOL_CONN_ACTIVE; - g_queue_push_tail_link (elt->active, conn_entry); - msg_debug_rpool ("reused existing connection to %s:%d: %p", - ip, port, conn->ctx); + /* Also check SO_ERROR */ + gint err; + socklen_t len = sizeof (gint); + + if (getsockopt (conn->ctx->c.fd, SOL_SOCKET, SO_ERROR, + (void *) &err, &len) == -1) { + err = errno; + } + + if (err != 0) { + g_list_free (conn->entry); + conn->entry = NULL; + REF_RELEASE (conn); + conn = rspamd_redis_pool_new_connection (pool, elt, + db, password, ip, port); + } + else { + + ev_timer_stop (elt->pool->event_loop, &conn->timeout); + conn->state = RSPAMD_REDIS_POOL_CONN_ACTIVE; + g_queue_push_tail_link (elt->active, conn_entry); + msg_debug_rpool ("reused existing connection to %s:%d: %p", + ip, port, conn->ctx); + } } else { g_list_free (conn->entry);