aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2020-03-31 12:09:24 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2020-03-31 12:09:24 +0100
commitbc17f9f5d0a3ceef09de1a9b367851b4dd15ef56 (patch)
treee9db23e4b89b405adda2ed011a2e5249171ed495 /src
parent447b68f3590279d3009d342addc575fbbe6735f3 (diff)
downloadrspamd-bc17f9f5d0a3ceef09de1a9b367851b4dd15ef56.tar.gz
rspamd-bc17f9f5d0a3ceef09de1a9b367851b4dd15ef56.zip
[Minor] Check for socket error before reusing keep-alive connection
Diffstat (limited to 'src')
-rw-r--r--src/libserver/http/http_context.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/libserver/http/http_context.c b/src/libserver/http/http_context.c
index 2863c0fbc..761760b5a 100644
--- a/src/libserver/http/http_context.c
+++ b/src/libserver/http/http_context.c
@@ -415,12 +415,32 @@ rspamd_http_context_check_keepalive (struct rspamd_http_context *ctx,
if (g_queue_get_length (conns) > 0) {
struct rspamd_http_keepalive_cbdata *cbd;
struct rspamd_http_connection *conn;
+ gint err;
+ socklen_t len = sizeof (gint);
cbd = g_queue_pop_head (conns);
rspamd_ev_watcher_stop (ctx->event_loop, &cbd->ev);
conn = cbd->conn;
g_free (cbd);
+ if (getsockopt(conn->fd, SOL_SOCKET, SO_ERROR, (void *) &err, &len) == -1) {
+ err = errno;
+ }
+
+ if (err != 0) {
+ rspamd_http_connection_unref (conn);
+
+ msg_debug_http_context ("invalid reused keepalive element %s (%s); "
+ "%s error; "
+ "%d connections queued",
+ rspamd_inet_address_to_string_pretty (phk->addr),
+ phk->host,
+ g_strerror (err),
+ conns->length);
+
+ return NULL;
+ }
+
msg_debug_http_context ("reused keepalive element %s (%s), %d connections queued",
rspamd_inet_address_to_string_pretty (phk->addr),
phk->host, conns->length);