Skip to content

Commit

Permalink
fix: prevent calling uv.run while already running.
Browse files Browse the repository at this point in the history
As documented, uv_run is NOT re-entrant and this
prevents this from happening by returning fail.

Each lua state has its own uv loop, so the only way
for this to happen is for uv.run to be called from
a libuv callback.
  • Loading branch information
truemedian committed Nov 20, 2024
1 parent 258831e commit 1ddd3fb
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ static const char *const luv_runmodes[] = {
static int luv_run(lua_State* L) {
int mode = luaL_checkoption(L, 1, "default", luv_runmodes);
luv_ctx_t* ctx = luv_context(L);
if (ctx->mode != -1) {
lua_pushnil(L);
lua_pushstring(L, "loop already running");
return 2;
}
ctx->mode = mode;
int ret = uv_run(ctx->loop, (uv_run_mode)mode);
ctx->mode = -1;
Expand Down

0 comments on commit 1ddd3fb

Please sign in to comment.