From 026cd801d7767c3fc5307c35049bd63e17edced3 Mon Sep 17 00:00:00 2001 From: dmiller Date: Tue, 4 Jan 2022 18:10:44 +0000 Subject: [PATCH] NSE nsock event handling improvements If an event is canceled, report it to the waiting thread as an error. Previous behavior left a waiting thread waiting forever, so NSE never stopped. If the event is killed, that means Nsock is being shut down, so this is coming from the garbage collection handler and we don't want to restore anything. Just return instead. --- nse_nsock.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/nse_nsock.cc b/nse_nsock.cc index fb17c3a8d..edfdb5124 100644 --- a/nse_nsock.cc +++ b/nse_nsock.cc @@ -334,8 +334,8 @@ static void status (lua_State *L, enum nse_status status) nse_restore(L, 1); break; case NSE_STATUS_KILL: + return; case NSE_STATUS_CANCELLED: - return; /* do nothing! */ case NSE_STATUS_EOF: case NSE_STATUS_ERROR: case NSE_STATUS_TIMEOUT: @@ -356,6 +356,8 @@ static void callback (nsock_pool nsp, nsock_event nse, void *ud) { nse_nsock_udata *nu = (nse_nsock_udata *) ud; lua_State *L = nu->thread; + if (nse_status(nse) == NSE_STATUS_KILL) + return; assert(nse_type(nse) != NSE_TYPE_READ); if (lua_status(L) == LUA_OK && nse_status(nse) == NSE_STATUS_ERROR) { // Sometimes Nsock fails immediately and callback is called before @@ -790,6 +792,8 @@ static int sleep_destructor (lua_State *L) static void sleep_callback (nsock_pool nsp, nsock_event nse, void *ud) { lua_State *L = (lua_State *) ud; + if (nse_status(nse) == NSE_STATUS_KILL) + return; assert(lua_status(L) == LUA_YIELD); assert(nse_status(nse) == NSE_STATUS_SUCCESS); nse_restore(L, 0);