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 3 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
13 changes: 6 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 + 4;
Copy link
Member

Choose a reason for hiding this comment

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

Better keep the parens otherwise we need to update this plan every time we change the repeat_each number. Also, the repeat each number is automatically increased on the "check leak" test mode of Test::Nginx::Socket, and your change will break the test plan in that test mode.


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

Expand Down Expand Up @@ -281,7 +281,7 @@ GET /lua
end)
end

N = 10
N = 10
Copy link
Member

Choose a reason for hiding this comment

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

Better avoid unrelated changes to make your changeset atomic. It's better for version control.

Copy link
Member Author

@bungle bungle Jan 14, 2017

Choose a reason for hiding this comment

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

I think my editor did it automatically. I will add that space back.

x = gen(N) -- generate primes up to N
while 1 do
local n = x() -- pick a number until done
Expand Down Expand Up @@ -483,8 +483,8 @@ done
GET /lua
--- response_body
hello
--- error_log eval
["stack traceback:", "coroutine 0:", "coroutine 1:", "coroutine 2:"]
--- no_error_log
[error]
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, the indentation of this test case is to test the Lua land backtrace. After your change, we no longer have any tests designed for this purpose.

I'm not sure if silencing the error logging is a good idea. Maybe we can make it a lower log level like "warn" or even "info"?

Copy link
Member

Choose a reason for hiding this comment

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

Also, better check the return values of coroutine.resume for better test coverage.

Copy link
Member Author

Choose a reason for hiding this comment

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

coroutine.resume is a pcall and its purpose is to catch the errors aka silence the errors and let users handle them. I will make that test better so it checks the return value.




Expand Down Expand Up @@ -901,8 +901,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 Expand Up @@ -1315,4 +1315,3 @@ co yield: 2

--- no_error_log
[error]