]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Minor] Check socket error when reusing redis pool connections
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 31 Mar 2020 11:19:59 +0000 (12:19 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 31 Mar 2020 11:19:59 +0000 (12:19 +0100)
src/libserver/http/http_context.c
src/libserver/redis_pool.c

index 761760b5aeffe20b9fcada73740a5468c34b5c53..c6119eeca7de1b66e8922feb096cc34fcbe7c27f 100644 (file)
@@ -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;
                        }
 
index 57fc734f9af89eb2b88be48243b99750fdce4f14..4d1a186762c380357621267749d387272c114e5d 100644 (file)
@@ -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);