diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2020-03-31 12:19:59 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2020-03-31 12:19:59 +0100 |
commit | fad056e59bea821222f9f4123550dd424e0836f5 (patch) | |
tree | be7c2b8105bc4fb5fd96f9b07dace3765d5b498b | |
parent | bc17f9f5d0a3ceef09de1a9b367851b4dd15ef56 (diff) | |
download | rspamd-fad056e59bea821222f9f4123550dd424e0836f5.tar.gz rspamd-fad056e59bea821222f9f4123550dd424e0836f5.zip |
[Minor] Check socket error when reusing redis pool connections
-rw-r--r-- | src/libserver/http/http_context.c | 2 | ||||
-rw-r--r-- | src/libserver/redis_pool.c | 29 |
2 files changed, 25 insertions, 6 deletions
diff --git a/src/libserver/http/http_context.c b/src/libserver/http/http_context.c index 761760b5a..c6119eeca 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 57fc734f9..4d1a18676 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); |