Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: not exit when error occurs in callback #664

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lhandle.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ static void luv_call_callback(lua_State* L, luv_handle_t* data, luv_callback_id
lua_insert(L, -1 - nargs);
}

ctx->cb_pcall(L, nargs, 0, 0);
ctx->cb_pcall(L, nargs, 0, LUVF_CALLBACK_FLAGS);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ static void luv_walk_cb(uv_handle_t* handle, void* arg) {

lua_pushvalue(L, 1); // Copy the function
luv_find_handle(L, data); // Get the userdata
data->ctx->cb_pcall(L, 1, 0, 0); // Call the function
data->ctx->cb_pcall(L, 1, 0, LUVF_CALLBACK_FLAGS); // Call the function
}

static int luv_walk(lua_State* L) {
Expand Down
2 changes: 1 addition & 1 deletion src/lreq.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ static void luv_fulfill_req(lua_State* L, luv_req_t* data, int nargs) {
if (nargs) {
lua_insert(L, -1 - nargs);
}
data->ctx->cb_pcall(L, nargs, 0, 0);
data->ctx->cb_pcall(L, nargs, 0, LUVF_CALLBACK_FLAGS);
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/luv.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@
#define LUVF_CALLBACK_NOTRACEBACK 0x02 // Don't traceback when error
#define LUVF_CALLBACK_NOERRMSG 0x04 // Don't output err message

#ifndef LUVF_CALLBACK_FLAGS
#define LUVF_CALLBACK_FLAGS LUVF_CALLBACK_NOEXIT
#endif

/* Prototype of external callback routine.
* The caller and the implementer exchanges data by the lua vm stack.
* The caller push a lua function and nargs values onto the stack, then call it.
Expand Down
2 changes: 1 addition & 1 deletion src/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ static void luv_thread_cb(void* varg) {
//push parameter for real thread function
int i = luv_thread_arg_push(L, &thd->args, LUVF_THREAD_SIDE_CHILD);

ctx->thrd_pcall(L, i, 0, 0);
ctx->thrd_pcall(L, i, 0, LUVF_CALLBACK_NOEXIT);
luv_thread_arg_clear(L, &thd->args, LUVF_THREAD_SIDE_CHILD);
} else {
fprintf(stderr, "Uncaught Error in thread: %s\n", lua_tostring(L, -1));
Expand Down
2 changes: 1 addition & 1 deletion src/work.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ static void luv_after_work_cb(uv_work_t* req, int status) {

lua_rawgeti(L, LUA_REGISTRYINDEX, ctx->after_work_cb);
i = luv_thread_arg_push(L, &work->rets, LUVF_THREAD_SIDE_MAIN);
lctx->cb_pcall(L, i, 0, 0);
lctx->cb_pcall(L, i, 0, LUVF_CALLBACK_FLAGS);

//ref down to ctx, up in luv_queue_work()
luaL_unref(L, LUA_REGISTRYINDEX, work->ref);
Expand Down
11 changes: 11 additions & 0 deletions tests/test-prepare-check-idle-async.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,15 @@ return require('lib/tap')(function (test)
uv.async_send(async)
end)

test("error occurs in idle callback", function (print, p, expect, uv)
local idle = uv.new_idle()
uv.idle_start(idle, expect(function ()
p("idle", idle)
uv.idle_stop(idle)
uv.close(idle, expect(function ()
end))
error("Error in idle callback")
end))
end)

end)
8 changes: 8 additions & 0 deletions tests/test-timer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,12 @@ return require('lib/tap')(function (test)
assert(huge_timer:get_due_in()==0xffff)
end, "1.40.0")

test("timer init", function(print, p, expect, uv)
local timer = uv.new_timer()
timer:start(10, 0, function()
timer:stop()
timer:close()
error('Error in timeout callback')
end)
end)
end)
Loading