Skip to content

Commit

Permalink
[Fix] Lua_tcp: Sigh, another try to fix close invocation
Browse files Browse the repository at this point in the history
  • Loading branch information
vstakhov committed Oct 21, 2022
1 parent bd2f3f1 commit 075fa9f
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/lua/lua_tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1044,6 +1044,11 @@ lua_tcp_process_read (struct lua_tcp_cbdata *cbd,
}
else {
lua_tcp_push_error (cbd, TRUE, "IO read error: connection terminated");

if ((cbd->flags & LUA_TCP_FLAG_FINISHED)) {
/* A callback has called `close` method, so we need to release a refcount */
TCP_RELEASE (cbd);
}
}

lua_tcp_plan_handler_event (cbd, FALSE, FALSE);
Expand All @@ -1067,6 +1072,11 @@ lua_tcp_process_read (struct lua_tcp_cbdata *cbd,
lua_tcp_push_error (cbd, TRUE,
"IO read error while trying to read data: %s",
strerror (errno));

if ((cbd->flags & LUA_TCP_FLAG_FINISHED)) {
/* A callback has called `close` method, so we need to release a refcount */
TCP_RELEASE (cbd);
}
}

lua_tcp_plan_handler_event (cbd, FALSE, FALSE);
Expand Down Expand Up @@ -1193,8 +1203,8 @@ lua_tcp_plan_handler_event (struct lua_tcp_cbdata *cbd, gboolean can_read,
if (!(cbd->flags & LUA_TCP_FLAG_FINISHED)) {
/* We are finished with a connection */
msg_debug_tcp ("no handlers left, finish session");
TCP_RELEASE (cbd);
cbd->flags |= LUA_TCP_FLAG_FINISHED;
TCP_RELEASE (cbd);
}
}
else {
Expand Down

0 comments on commit 075fa9f

Please sign in to comment.