]> source.dussan.org Git - rspamd.git/commitdiff
[Fix] Fix hang when close is used
authorVsevolod Stakhov <vsevolod@rspamd.com>
Wed, 5 Oct 2022 22:12:04 +0000 (23:12 +0100)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Wed, 5 Oct 2022 22:15:54 +0000 (23:15 +0100)
src/lua/lua_tcp.c

index 05c9de7a27dbb22e419444cb8dd3f55a8227445f..643978a49f9f41952939c71afc6a48d2cadfc2a2 100644 (file)
@@ -602,6 +602,12 @@ lua_tcp_push_error (struct lua_tcp_cbdata *cbd, gboolean is_fatal,
 
                        TCP_RELEASE (cbd);
 
+                       if ((cbd->flags & (LUA_TCP_FLAG_FINISHED|LUA_TCP_FLAG_CONNECTED)) ==
+                               (LUA_TCP_FLAG_FINISHED|LUA_TCP_FLAG_CONNECTED)) {
+                               /* A callback has called `close` method, so we need to release a refcount */
+                               TCP_RELEASE (cbd);
+                       }
+
                        callback_called = TRUE;
                }
 
@@ -694,6 +700,12 @@ lua_tcp_push_data (struct lua_tcp_cbdata *cbd, const guint8 *str, gsize len)
 
                lua_settop (L, top);
                TCP_RELEASE (cbd);
+
+               if ((cbd->flags & (LUA_TCP_FLAG_FINISHED|LUA_TCP_FLAG_CONNECTED)) ==
+                       (LUA_TCP_FLAG_FINISHED|LUA_TCP_FLAG_CONNECTED)) {
+                       /* A callback has called `close` method, so we need to release a refcount */
+                       TCP_RELEASE (cbd);
+               }
        }
 
        lua_thread_pool_restore_callback (&cbs);
@@ -1134,6 +1146,12 @@ lua_tcp_handler (int fd, short what, gpointer ud)
                                        lua_settop (L, top);
                                        TCP_RELEASE (cbd);
                                        lua_thread_pool_restore_callback (&cbs);
+
+                                       if ((cbd->flags & (LUA_TCP_FLAG_FINISHED|LUA_TCP_FLAG_CONNECTED)) ==
+                                               (LUA_TCP_FLAG_FINISHED|LUA_TCP_FLAG_CONNECTED)) {
+                                               /* A callback has called `close` method, so we need to release a refcount */
+                                               TCP_RELEASE (cbd);
+                                       }
                                }
                        }
                }