From 4a75d59ccf077d08ea33695df586d81345ed2f4c Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Fri, 9 Oct 2020 12:31:03 +0100 Subject: [Fix] Use dup fd in milter handler to avoid races with the proxy --- src/rspamd_proxy.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'src/rspamd_proxy.c') diff --git a/src/rspamd_proxy.c b/src/rspamd_proxy.c index 4ed8cfab7..3fa5da390 100644 --- a/src/rspamd_proxy.c +++ b/src/rspamd_proxy.c @@ -2150,18 +2150,29 @@ proxy_milter_finish_handler (gint fd, static void proxy_milter_error_handler (gint fd, - struct rspamd_milter_session *rms, + struct rspamd_milter_session *rms, /* unused */ void *ud, GError *err) { struct rspamd_proxy_session *session = ud; - msg_info_session ("abnormally closing milter connection from: %s, " - "error: %e", - rspamd_inet_address_to_string_pretty (session->client_addr), - err); - /* Terminate session immediately */ - proxy_backend_close_connection (session->master_conn); - REF_RELEASE (session); + if (err && err->code != 0) { + msg_info_session ("abnormally closing milter connection from: %s, " + "error: %e", + rspamd_inet_address_to_string_pretty (session->client_addr), + err); + /* Terminate session immediately */ + proxy_backend_close_connection (session->master_conn); + REF_RELEASE (session); + } + else { + msg_info_session ("normally closing milter connection from: %s, " + "%e", + rspamd_inet_address_to_string_pretty (session->client_addr), + err); + /* Terminate session immediately */ + proxy_backend_close_connection (session->master_conn); + REF_RELEASE (session); + } } static void -- cgit v1.2.3