commit fad056e: [Minor] Check socket error when reusing redis pool connections
Vsevolod Stakhov
vsevolod at highsecure.ru
Tue Mar 31 11:21:10 UTC 2020
Author: Vsevolod Stakhov
Date: 2020-03-31 12:19:59 +0100
URL: https://github.com/rspamd/rspamd/commit/fad056e59bea821222f9f4123550dd424e0836f5 (HEAD -> master)
[Minor] Check socket error when reusing redis pool connections
---
src/libserver/http/http_context.c | 2 +-
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);
More information about the Commits
mailing list