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

error when using with OpenResty cli #60

Closed
Tieske opened this issue Jul 16, 2018 · 5 comments
Closed

error when using with OpenResty cli #60

Tieske opened this issue Jul 16, 2018 · 5 comments

Comments

@Tieske
Copy link
Member

Tieske commented Jul 16, 2018

in function get_cur_dir I'm getting this error (I isolated it to the resty cli tool):

$ resty -e "local x = io.popen('pwd 2>/dev/null', 'r'); print(x:read())"
/Users/thijs/code/lua-resty-dns-client
$ resty -e "local x = io.popen('pwd 2>/dev/null', 'r'); print(x:read('*a'))"
nilInterrupted system call4
$

Somehow read("*a") from io.popen triggers the error, where read() succeeds

@hishamhm
Copy link
Member

This is an issue with the resty cli. The nginx event loop sends Unix signals and the Lua io library doesn't know about them (because it is OS-agnostic), so the underlying syscall used by io.popen halts with EINTR, and you get the error.

Given that resty is embedding Lua(JIT) in its signal-enabled Unix environment, it's their responsibility to ensure that the Lua they offer works correctly with the environment they're embedding it in. I believe @thibaultcha even sent a patch to OpenResty's repo of LuaJIT adding support for catching EINTR and retrying the C library call in (some?) io calls, which alleviates this issue. I'm afraid it breaks the ability to do Ctrl-C reliably, though. I'm not sure a fully clean solution to this is possible, signals are a pretty "meh" aspect of the Unix design.

In any case, this is not a luacov issue, so I think we can safely close this one. :)

@Tieske
Copy link
Member Author

Tieske commented Jul 17, 2018

Yes obviously that is the case. My point would be that we do not need "*a", just reading the first line (default behaviour of read iirc) should be enough.

@thibaultcha
Copy link

thibaultcha commented Jul 17, 2018

There is another series of patches addressing this (we reverted the retry on EINTR patch in LuaJIT). See openresty/lua-nginx-module#1296 and other linked PRs.

While the retry on EINTR patch could have been an issue in other applications embedding LuaJIT (I don't really think so), the SA_RESTART flag does not prevent the correct handling of SIGINT within Nginx as far as I remember.

@mpeterv
Copy link
Contributor

mpeterv commented Jul 17, 2018

If the workaround in luacov is so small and still reliable I think it's worth applying.

@hishamhm
Copy link
Member

@thibaultcha thanks for the update! that does sound like a good approach indeed.

@mpeterv @Tieske I don't think this is a reliable solution — it makes the problem less likely to hit, but I think it's still prone to EINTR. Still, the change is harmless so why not.

Tieske added a commit to Tieske/luacov that referenced this issue Jul 18, 2018
see lunarmodules#60. This will most likely not prevent the issue, but reduce the probability of it occurring .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants