-
Notifications
You must be signed in to change notification settings - Fork 2k
bugfix: coroutine.wrap: propagate errors to the parent coroutine. #1239
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
bugfix: coroutine.wrap: propagate errors to the parent coroutine. #1239
Conversation
1a71966
to
d7867b6
Compare
d7867b6
to
f62ae61
Compare
@agentzh Do you have any feedback on this? Considering it is a behavior mistmatch according to both the Lua and ngx_lua manuals, I was under the impression that it would be of a somewhat middle to high priority? |
f62ae61
to
7a69258
Compare
@thibaultcha This is a deep change. I'm not sure about it without thinking much longer about it. |
@thibaultcha Thank you for reporting this issue and contributing this patch! |
@agentzh Have you given more thought to this? Compatibility with Lua(JIT) is one of the goal we try to achieve with ngx_lua (as per previous incompatibilities we fixed) and that is why I believe this fix to be important. Thanks! |
@thibaultcha I understand but I have other higher priority things at the moment. Sorry. Will get back to this as soon as I can manage. |
75c0b3d
to
ac39640
Compare
ac39640
to
979f864
Compare
The manual states that coroutine.wrap is "Similar to the standard Lua API". However, the Lua API's
coroutine.wrap
has some nuances compared to the one provided by ngx_lua:Source (Lua 5.1 manual).
This caused me some issues in the daily job's latest release, where we expected errors encountered in
coroutine.wrap
to be propagated to the Lua main thread, and cause 500 errors. But those errors were swallowed by the thread "scheduler".Example:
With LuaJIT 2.1:
With our resty-cli utility:
Notice the
still running
line at the bottom.My initial fix for this was to edit the inline Lua code that creates
coroutine.wrap
so that it would propagate errors witherror(..., 2)
, but it is a less than ideal fix, since the error becomes logged twice (once in the coroutine context, and once in the parent context), like so:Additionally, dealing with it in the Lua land would have meant a lot of expensive operations with the variadic arguments/return values aspects of
coroutine.resume
(we would have had to deal withpack
,unpack
, et al.).Instead, I propose to get rid of the "hack" that is used to implement
coroutine.wrap
, and implement a version of it that embraces the ngx_lua threading model.