commit b5e12b9: [Project] More fixes to keepalive http pool

Vsevolod Stakhov vsevolod at highsecure.ru
Tue Mar 5 16:42:05 UTC 2019


Author: Vsevolod Stakhov
Date: 2019-03-05 16:19:14 +0000
URL: https://github.com/rspamd/rspamd/commit/b5e12b95ee564f58e41aa9a3058191bb10e2a9f0

[Project] More fixes to keepalive http pool

---
 src/libutil/http_connection.c |  7 +++++++
 src/libutil/http_context.c    | 12 +++++++++++-
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/src/libutil/http_connection.c b/src/libutil/http_connection.c
index 9e43e21e2..dc3bfa9c0 100644
--- a/src/libutil/http_connection.c
+++ b/src/libutil/http_connection.c
@@ -356,6 +356,7 @@ rspamd_http_on_headers_complete (http_parser * parser)
 		if (conn->opts & RSPAMD_HTTP_CLIENT_KEEP_ALIVE) {
 			rspamd_http_context_push_keepalive (conn->priv->ctx, conn,
 					msg, conn->priv->ctx->ev_base);
+			rspamd_http_connection_reset (conn);
 		}
 		else {
 			conn->finished = TRUE;
@@ -539,6 +540,7 @@ rspamd_http_on_headers_complete_decrypted (http_parser *parser)
 		if (conn->opts & RSPAMD_HTTP_CLIENT_KEEP_ALIVE) {
 			rspamd_http_context_push_keepalive (conn->priv->ctx, conn,
 					msg, conn->priv->ctx->ev_base);
+			rspamd_http_connection_reset (conn);
 		}
 		else {
 			conn->finished = TRUE;
@@ -697,6 +699,7 @@ rspamd_http_on_message_complete (http_parser * parser)
 		if (conn->opts & RSPAMD_HTTP_CLIENT_KEEP_ALIVE) {
 			rspamd_http_context_push_keepalive (conn->priv->ctx, conn,
 					priv->msg, conn->priv->ctx->ev_base);
+			rspamd_http_connection_reset (conn);
 		}
 		else {
 			conn->finished = TRUE;
@@ -1135,6 +1138,10 @@ rspamd_http_connection_new_keepalive (struct rspamd_http_context *ctx,
 		return NULL;
 	}
 
+	if (ctx == NULL) {
+		ctx = rspamd_http_context_default ();
+	}
+
 	conn = rspamd_http_context_check_keepalive (ctx, addr, host);
 
 	if (conn) {
diff --git a/src/libutil/http_context.c b/src/libutil/http_context.c
index d8b576d1f..7f1de0c36 100644
--- a/src/libutil/http_context.c
+++ b/src/libutil/http_context.c
@@ -78,6 +78,7 @@ rspamd_http_context_new_default (struct rspamd_config *cfg,
 
 	static const int default_kp_size = 1024;
 	static const gdouble default_rotate_time = 120;
+	static const gdouble default_keepalive_interval = 65;
 	static const gchar *default_user_agent = "rspamd-" RSPAMD_VERSION_FULL;
 
 	ctx = g_malloc0 (sizeof (*ctx));
@@ -85,6 +86,7 @@ rspamd_http_context_new_default (struct rspamd_config *cfg,
 	ctx->config.kp_cache_size_server = default_kp_size;
 	ctx->config.client_key_rotate_time = default_rotate_time;
 	ctx->config.user_agent = default_user_agent;
+	ctx->config.keepalive_interval = default_keepalive_interval;
 
 	if (cfg) {
 		ctx->ssl_ctx = cfg->libs_ctx->ssl_ctx;
@@ -171,6 +173,14 @@ rspamd_http_context_create (struct rspamd_config *cfg,
 					ctx->config.user_agent = NULL;
 				}
 			}
+
+			const ucl_object_t *keepalive_interval;
+
+			keepalive_interval = ucl_object_lookup (client_obj, "keepalive_interval");
+
+			if (keepalive_interval) {
+				ctx->config.keepalive_interval = ucl_object_todouble (keepalive_interval);
+			}
 		}
 
 		server_obj = ucl_object_lookup (http_obj, "server");
@@ -443,7 +453,7 @@ rspamd_http_context_push_keepalive (struct rspamd_http_context *ctx,
 
 	event_set (&cbdata->ev, conn->fd, EV_READ|EV_TIMEOUT,
 			rspamd_http_keepalive_handler,
-			&cbdata);
+			cbdata);
 
 	double_to_tv (timeout, &tv);
 	event_base_set (ev_base, &cbdata->ev);


More information about the Commits mailing list