luvit/luv

track issues in neovim related with luv

zhaozg opened this issue · 4 comments

zhaozg commented

This mainly because of default behavior of luv will exit when error occurs in callback.

luv/src/luv.c

Lines 707 to 724 in bc01ad8

case LUA_ERRMEM:
if ((flags & LUVF_CALLBACK_NOERRMSG) == 0)
fprintf(stderr, "System Error: %s\n", lua_tostring(L, -1));
if ((flags & LUVF_CALLBACK_NOEXIT) == 0)
exit(-1);
lua_pop(L, 1);
ret = -ret;
break;
case LUA_ERRRUN:
case LUA_ERRERR:
default:
if ((flags & LUVF_CALLBACK_NOERRMSG) == 0)
fprintf(stderr, "Uncaught Error: %s\n", lua_tostring(L, -1));
if ((flags & LUVF_CALLBACK_NOEXIT) == 0)
exit(-1);
lua_pop(L, 1);
ret = -ret;
break;

There are three opportunity or choice to handle this kind things.

1. The Lua developer has duty to write safe callback code.

2. The applications that use luv can use can change luv default process by luv c api.

luv/src/luv.h

Lines 124 to 141 in bc01ad8

/* Set or clear an external c routine for luv event callback
When using a custom/external function, this must be called before luaopen_luv
(otherwise luv will use the default callback function: luv_cfpcall)
*/
LUALIB_API void luv_set_callback(lua_State* L, luv_CFpcall pcall);
/* Set or clear an external c routine for luv thread When using
* a custom/external function, this must be called before luaopen_luv
* in the function that create the lua_State of the thread
(otherwise luv will use the default callback function: luv_cfpcall)
*/
LUALIB_API void luv_set_thread(lua_State* L, luv_CFpcall pcall);
/* Set or clear an external c routine for luv c thread When using
* a custom/external function, this must be called before luaopen_luv
* in the function that create the lua_State of the thread
(otherwise luv will use the default callback function: luv_cfcpcall)
*/

luv flags to control luv_CFpcall routine.

https://github.com/luvit/luv/blob/master/src/luv.h#L65-L93

3. luv set default flag with LUVF_CALLBACK_NOEXIT to avoid exit, continue to run but real errors

This is simplest way, but when luv use as a network server live long time, this maybe hide some applications errors. I hope receive more recommendations about whether to enable this.

Let's try change default LUVF_CALLBACK_FLAGS to LUVF_CALLBACK_NOEXIT.

Let's try change default LUVF_CALLBACK_FLAGS to LUVF_CALLBACK_NOEXIT.

This just runs into #433 again, see #433 (comment) for the problem with it.

Note also that neovim does not use the default luv_cfpcall, so fixing the non-string error problems on our end won't actually fix them for neovim.

zhaozg commented

Let's try change default LUVF_CALLBACK_FLAGS to LUVF_CALLBACK_NOEXIT.

This just runs into #433 again, see #433 (comment) for the problem with it.

I almost forget that.