]> source.dussan.org Git - rspamd.git/commitdiff
[Fix] Lua_tcp: Make write errors fatal and rework error handlers
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 18 Oct 2019 11:08:55 +0000 (12:08 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 18 Oct 2019 11:08:55 +0000 (12:08 +0100)
Issue: #3097

src/lua/lua_tcp.c

index 379d3d8075d0754cffa8d86d1831c2cfd27052e6..335d770d5bf65e5a31ff2413f6a1f2985643ad94 100644 (file)
@@ -535,6 +535,7 @@ lua_tcp_push_error (struct lua_tcp_cbdata *cbd, gboolean is_fatal,
        gint cbref, top;
        struct lua_callback_state cbs;
        lua_State *L;
+       gboolean callback_called = FALSE;
 
        if (cbd->thread) {
                va_start (ap, err);
@@ -591,11 +592,19 @@ lua_tcp_push_error (struct lua_tcp_cbdata *cbd, gboolean is_fatal,
                        lua_settop (L, top);
 
                        TCP_RELEASE (cbd);
+
+                       callback_called = TRUE;
                }
 
                if (!is_fatal) {
-                       /* Stop on the first callback found */
-                       break;
+                       if (callback_called) {
+                               /* Stop on the first callback found */
+                               break;
+                       }
+                       else {
+                               /* Shift to another callback to inform about fatal error */
+                               continue;
+                       }
                }
                else {
                        lua_tcp_shift_handler (cbd);
@@ -841,14 +850,12 @@ lua_tcp_write_helper (struct lua_tcp_cbdata *cbd)
 
        if (r == -1) {
                if (!(cbd->ssl_conn)) {
-                       lua_tcp_push_error (cbd, FALSE,
+                       lua_tcp_push_error (cbd, TRUE,
                                        "IO write error while trying to write %d bytes: %s",
                                        (gint) remain, strerror (errno));
-                       if (!IS_SYNC (cbd)) {
-                               /* sync connection methods perform this inside */
-                               lua_tcp_shift_handler (cbd);
-                               lua_tcp_plan_handler_event (cbd, TRUE, FALSE);
-                       }
+
+                       msg_debug_tcp ("write error, terminate connection");
+                       TCP_RELEASE (cbd);
                }
 
                return;