From 3a528e1d1d9394cd2bad37e73b926aac8d08e89f Mon Sep 17 00:00:00 2001 From: dmiller Date: Tue, 5 May 2026 20:58:56 +0000 Subject: [PATCH] Correctly continue receive_buf on immediate error/success --- nse_nsock.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/nse_nsock.cc b/nse_nsock.cc index 6780d8bb4..5791fe635 100644 --- a/nse_nsock.cc +++ b/nse_nsock.cc @@ -792,12 +792,12 @@ static int receive_buf (lua_State *L, int status, lua_KContext ctx) else { lua_pop(L, 2); /* pop 2 results */ - int oldtop = lua_gettop(L); nu->action = "RECEIVE BUF"; nsock_read(nsp, nu->nsiod, receive_callback, nu->timeout, nu); if (nu->action == NU_ACTION_IMMEDIATE) { - // Immediate return - return lua_gettop(L) - oldtop; + // Immediate return. We can't yield since the callback already ran, so we + // call ourselves as a continuation just like Lua would have. + return receive_buf(L, LUA_YIELD, 0); } return yield(L, nu, "RECEIVE BUF", FROM, 0, receive_buf); }