Skip to content

No error logging on coroutine.resume (pull-request for issue #951) #952

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

Closed
wants to merge 6 commits 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
3 changes: 0 additions & 3 deletions src/ngx_http_lua_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -1437,9 +1437,6 @@ ngx_http_lua_run_thread(lua_State *L, ngx_http_request_t *r,

ctx->cur_co_ctx = next_coctx;

ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
"lua coroutine: %s: %s\n%s", err, msg, trace);

/* try resuming on the new coroutine again */
continue;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I mentioned earlier, should we just lower the log level here? Like info?

Copy link
Member Author

@bungle bungle Jan 15, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we do so, this will be different than what Lua / LuaJIT does. They don't write anything. I mean, OpenResty doesn't log anything when wrapping code with pcall. If you want to log errors even when they are raised in a code wrapped with pcall, then I would consider having this logged as well, and of course we need to change pcall then as well. This would differ from what users' expect, though. My only concern is that I'm not sure if that removed log entry removes error logging also from some case where it shouldn't. That's why I asked do anyone of you know if it is only handling when users' code calls coroutine.resume (that's the only place where this logging should be silenced).

But I probably wouldn't worry too much if this is lowered to INFO or even DEBUG. Some library writers can rely on this, e.g. exiting coroutines with error and then handling the errors themselves. If this means that the logs will be filled with these messages, then that could be a problem. E.g. my routing library is relying on coroutines and it will by default log the errors from coroutine.resume, so this would mean that errors are logged twice.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bungle pcall is a more explicit try/catch in the Lua world while many Lua programmers may overlook the error handling in coroutine.resume.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@agentzh, I agree, but that's how the Lua is. Those that use coroutine.resume should know that it is effectively a pcall. There is some history to this as pcall has not been fully compatible with coroutines (http://lua-users.org/wiki/PcallAndCoroutines).

}
Expand Down
17 changes: 10 additions & 7 deletions t/091-coroutine.t
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use Test::Nginx::Socket::Lua;

repeat_each(2);

plan tests => repeat_each() * (blocks() * 3 + 5);
plan tests => repeat_each() * (blocks() * 3 + 2);

$ENV{TEST_NGINX_RESOLVER} ||= '8.8.8.8';

Expand Down Expand Up @@ -470,21 +470,24 @@ done
--- config
location /lua {
content_by_lua '
local f = function(cr) coroutine.resume(cr) end
local f = function(cr) return coroutine.resume(cr) end
-- emit a error
local g = function() unknown.unknown = 1 end
local l1 = coroutine.create(f)
local l2 = coroutine.create(g)
coroutine.resume(l1, l2)
ngx.say("hello")
local o, k, e = coroutine.resume(l1, l2)
ngx.say(o and not k and "hello" or "failed")
if e then
ngx.log(ngx.ERR, e)
end
';
}
--- request
GET /lua
--- response_body
hello
--- error_log eval
["stack traceback:", "coroutine 0:", "coroutine 1:", "coroutine 2:"]
["attempt to index global 'unknown' (a nil value)"]



Expand Down Expand Up @@ -901,8 +904,8 @@ qr/^child: resume: falsecontent_by_lua\(nginx\.conf:\d+\):4: bad
child: status: dead
parent: status: running
$/s
--- error_log eval
qr/lua coroutine: runtime error: content_by_lua\(nginx\.conf:\d+\):4: bad/
--- no_error_log
[error]



Expand Down