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

feature: introduced the 'lua_sa_restart' directive, which sets the SA_RESTART flag on nginx workers signal dispositions. #1296

Merged
merged 1 commit into from
Nov 13, 2018

Conversation

thibaultcha
Copy link
Member

@thibaultcha thibaultcha commented Apr 10, 2018

This is one of 4 PRs to properly handle EINTR errors in resty-cli (and/or OpenResty if desired by the user).

If all PRs are merged:

src/ngx_http_lua_worker.c Outdated Show resolved Hide resolved
src/ngx_http_lua_worker.c Outdated Show resolved Hide resolved
struct sigaction act;

if (ngx_process != NGX_PROCESS_WORKER
&& ngx_process != NGX_PROCESS_SINGLE)
Copy link
Member

Choose a reason for hiding this comment

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

We need to take into account the privileged agent helper process here.

@agentzh
Copy link
Member

agentzh commented Jun 29, 2018

@thibaultcha I think it's better to simply enable SA_RESTART in our lua module's init worker hook on the C land? It's a burden for the user to always remember calling a Lua API in their own init_worker_by_lua* handler.

@thibaultcha
Copy link
Member Author

@agentzh Does this list sound good for the set of signals the SA_RESTART flag is to be enabled by default: https://github.com/openresty/resty-cli/pull/41/files#diff-f40cddd047a559bb89d08b41dfdfd86dR625 ?

@thibaultcha
Copy link
Member Author

I must admit that for the sake of backwards-compatibility (in the event of an unforeseen issue), I was under the impression that we would not enable this flag on any signal by default - especially considering it is enabled by default in resty-cli (as per openresty/resty-cli#41), where it matters the most.

But I am fine enabling it by default in this module's init context, no problem (if the suggested list of signals is good to go).

@agentzh
Copy link
Member

agentzh commented Jun 30, 2018

@thibaultcha That list looks good to me. This is also important for non-resty-cli contexts. I don't like enabling by hand, which is too easy to miss for average users. And it does not look like there is any unwanted side effects so there's no backward compatibility that we need to preserve here?

@dndx
Copy link
Member

dndx commented Jun 30, 2018

@thibaultcha I think at least we should include the signals found in http://lxr.nginx.org/source/src/os/unix/ngx_process.c#0039. The last two are not needed since they are ignored already.

@thibaultcha
Copy link
Member Author

@agentzh @dndx I have reworked the PR and other related ones. So far, this PR sets the SA_RESTART flag upon worker initialization, and exposes an FFI API that openresty/lua-resty-core#183 can consume. openresty/resty-cli#41 now simply adds regression tests for the EINTR error on file handle reads (still needs docs & tests if we are exposing the Lua-land API).

I do wonder if maintaining a patch adding the SA_RESTART flag in ngx_init_signals would be easier? But the FFI API is a nice-to-have anyway I think.

@thibaultcha
Copy link
Member Author

@agentzh @dndx Ping here :)

Also maybe #1239 as well, which I still consider quite important for true Lua compatibility.

@thibaultcha thibaultcha force-pushed the feat/sa-restart branch 3 times, most recently from 5a7e66b to f928849 Compare September 5, 2018 02:20
@thibaultcha
Copy link
Member Author

Patch updated:

I did like the granularity offered by the FFI API (being able to set/unset this flag as desired on a per-signal basis), but I removed it to show what a minimal patch would look like. I can add the FFI back any time if desired.

src/ngx_http_lua_module.c Show resolved Hide resolved
@@ -70,6 +70,25 @@
#endif


#if !(NGX_WIN32)
Copy link
Member

Choose a reason for hiding this comment

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

I suggest we do feature test instead of excluding just win32 here for better portability.

@thibaultcha
Copy link
Member Author

@agentzh Updated with a feature test. Mind having another look? If ready, I will port this PR to the meta-lua module as well.

@thibaultcha thibaultcha changed the title feature: added an FFI API for setting the SA_RESTART flag on signals feature: introduced the 'lua_sa_restart' directive, which sets the SA_RESTART flag on nginx workers signal dispositions. Nov 7, 2018
Copy link
Member

@agentzh agentzh left a comment

Choose a reason for hiding this comment

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

Should add some docs. Otherwise it looks good to me.

@thibaultcha
Copy link
Member Author

Pushed some documentation.

"setting SA_RESTART for signal %d", *signo);

if (sigaction(*signo, NULL, &act) != 0) {
ngx_log_error(NGX_LOG_WARN, log, 0, "failed to get sigaction for "
Copy link
Member

Choose a reason for hiding this comment

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

Should use the errno arg directly.

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 Updated

… SA_RESTART flag on nginx workers signal dispositions.
@thibaultcha thibaultcha merged commit 2f7c650 into openresty:master Nov 13, 2018
@thibaultcha thibaultcha deleted the feat/sa-restart branch November 13, 2018 02:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants