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

DNS network syscalls failing when falling back to secondary nameservers #73

Closed
satom99 opened this issue Feb 27, 2017 · 11 comments
Closed

Comments

@satom99
Copy link

satom99 commented Feb 27, 2017

local ws = require('http.websocket')
local socket = ws.new_from_uri('wss://gateway.discord.gg')
print( socket:connect(15) )
-- nil     starttls: Invalid argument      22

After a fresh Lua and luarocks installation this error occurs. Probably has to do with cqueues but posting here just in case.

EDIT: Seems to work fine on Ubuntu, this error is proven to fire on Debian.

Also, after installing using luarocks, the module is eventually named after http_0_1_0-http and not http as expected.

@daurnimator
Copy link
Owner

After a fresh Lua and luarocks installation this error occurs.

Could you show me output of luarocks show http?
Can you confirm that is the local copy in use? (e.g. run strace -e open lua -l http.websocket < /dev/null |& grep websocket.lua)

starttls: Invalid argument

Do you any "Invalid argument" errors if you connect to a non-wss websocket?
e.g. try with ws://echo.websocket.org

EDIT: Seems to work fine on Ubuntu, this error is proven to fire on Debian.

FWIW it works fine for me locally

Also, after installing using luarocks, the module is eventually named after http_0_1_0-http and not http as expected.

I notice luarocks will do that if a 'http' module already exists (e.g. if you've installed via apt/dpkg). @hisham ping?

@satom99
Copy link
Author

satom99 commented Feb 28, 2017

Could you show me output of luarocks show http?

Here, keep in mind that's right after renaming its folder to http (in order to get round the naming issue already stated). Plus, naming being an issue proves it being the copy in use.

When connecting to ws://echo.websocket.org, the following is printed:

nil flush: Invalid argument 22

It works fine for me locally too, perhaps it's an isolated issue having to do with that Debian VM?

@daurnimator
Copy link
Owner

daurnimator commented Feb 28, 2017

When connecting to ws://echo.websocket.org, the following is printed:

nil flush: Invalid argument 22

That's good to know: the issue isn't in TLS negotiation.

Could you run it again with the environmental variable SOCKET_DEBUG=1 set?
e.g. SOCKET_DEBUG=1 lua myscript.lua

It works fine for me locally too, perhaps it's an isolated issue having to do with that Debian VM?

Perhaps, I'm wondering if maybe something weird going on with dns there?
Next step depending on what SOCKET_DEBUG does for you would be to investigate what DNS is doing

@satom99
Copy link
Author

satom99 commented Feb 28, 2017

SOCKET_DEBUG=1 lua myscript.lua

Getting the following, before nil flush is printed;

write([unknown]): Invalid argument

@daurnimator
Copy link
Owner

interesting.... Can you run under strace?

@satom99
Copy link
Author

satom99 commented Feb 28, 2017

Added it to the same gist. Reading through, looks like some files aren't found.

@daurnimator
Copy link
Owner

daurnimator commented Feb 28, 2017

The error is coming from here.

`connect(3, {sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr("62.210.16.6")}, 16) = -1 EINVAL (Invalid argument)`

Looking up higher, I see that the same fd was previously used for another request:

socket(PF_INET, SOCK_DGRAM|SOCK_CLOEXEC|SOCK_NONBLOCK, IPPROTO_IP) = 3
bind(3, {sa_family=AF_INET, sin_port=htons(57997), sin_addr=inet_addr("0.0.0.0")}, 16) = 0
connect(3, {sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr("127.0.0.1")}, 16) = 0

I wonder if your OS doesn't like connect() on the same UDP socket more than once?
Could you provide your versions of debian, linux and glibc?

@wahern ping

@satom99
Copy link
Author

satom99 commented Feb 28, 2017

cat /etc/*release
PRETTY_NAME="Debian GNU/Linux 8 (jessie)"

cat /proc/version
Linux version 4.4.35-1-pve (root@elsa) (gcc version 4.9.2 (Debian 4.9.2-10) )

ldd --version
ldd (Debian GLIBC 2.19-18+deb8u7) 2.19

@daurnimator
Copy link
Owner

daurnimator commented Feb 28, 2017

Oh, I just noticed the

recvfrom(3, 0x101ba8c, 768, 0, 0, 0) = -1 ECONNREFUSED (Connection refused)

Which is an instance of wahern/cqueues#167.
That might not be the cause of the EINVAL though.

@daurnimator
Copy link
Owner

as far as I can tell, this a bug in cqueue's behaviour (or infact, dns.c) and should be followed up there.

I think this is due to your /etc/resolv.conf containing a local resolver (e.g. 127.0.0.1) followed by another (working) server, and that your local dns resolver is not running.
A workaround would be to remove the local resolver from /etc/resolv.conf, or to make sure it's running.

@daurnimator
Copy link
Owner

Closing as bug has been reported to cqueues/dns.c

@daurnimator daurnimator changed the title starttls: Invalid argument DNS network syscalls failing when falling back to secondary nameservers Jun 16, 2018
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

No branches or pull requests

2 participants