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

Connection fails with "flush: Address family not supported by protocol" #186

Closed
edubart opened this issue Jun 8, 2017 · 6 comments
Closed

Comments

@edubart
Copy link

edubart commented Jun 8, 2017

Running the example simple.get I get the following error:

luajit: simple.get:47: cqueue: simple.get:18: socket:flush: Address family not supported by protocol
stack traceback:
	[C]: in function 'error'
	lala.lua:47: in main chunk
	[C]: at 0x00405b50

I am unable to connect to anything because of this.

My OS:

$ uname -a
Linux archlinux 4.11.3-1-ARCH #1 SMP PREEMPT Sun May 28 10:40:17 CEST 2017 x86_64 GNU/Linux
$ ldd --version
ldd (GNU libc) 2.25
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Roland McGrath and Ulrich Drepper.

@edubart
Copy link
Author

edubart commented Jun 8, 2017

Running strace I've found:

recvfrom(3, "d\301\201\200\0\1\0\1\0\0\0\0\7example\3com\0\0\1\0\1\300\f\0"..., 768, 0, NULL, NULL) = 45
socket(AF_UNSPEC, SOCK_STREAM|SOCK_CLOEXEC, 0) = -1 EAFNOSUPPORT (Address family not supported by protocol)

The code line socket(AF_UNSPEC, SOCK_STREAM|SOCK_CLOEXEC, 0) does not work in my system, simple test case in C:

#include <sys/socket.h>
#include <stdio.h>
#include <string.h>

int main() {
    printf("%d", socket(AF_UNSPEC, SOCK_STREAM|SOCK_CLOEXEC, 0));
    perror("socket error");
    return 0;
}

Output:

$ gcc test.c -o test && ./test
socket error: Address family not supported by protocol
-1

@jdesgats
Copy link

Had the exact same issue with Arch, the most confusiong thing was that my debug build using my own fork of cqueues were still working.
I eventually tracked this down to the default compilation flags in Luarocsk: it copiles with -O2 by default, overriding this with -O0 produces a working binary.

$ LC_ALL=C gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/7.1.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /build/gcc-multilib/src/gcc/configure --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/ --enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++ --enable-shared --enable-threads=posix --enable-libmpx --with-system-zlib --with-isl --enable-__cxa_atexit --disable-libunwind-exceptions --enable-clocale=gnu --disable-libstdcxx-pch --disable-libssp --enable-gnu-unique-object --enable-linker-build-id --enable-lto --enable-plugin --enable-install-libiberty --with-linker-hash-style=gnu --enable-gnu-indirect-function --enable-multilib --disable-werror --enable-checking=release
Thread model: posix
gcc version 7.1.1 20170528 (GCC) 

$ make clean && rm -fr /tmp/test && make install5.3 prefix=/tmp/test CFLAGS=-O2
...
$ LUA_PATH='/tmp/test/share/lua/5.3/?.lua;;' LUA_CPATH='/tmp/test/lib/lua/5.3/?.so' strace -e network lua -e 's=require("cqueues.socket"); print(s.listen("127.0.0.1", 4000):accept())'
socket(AF_UNSPEC, SOCK_STREAM|SOCK_CLOEXEC, 0) = -1 EAFNOSUPPORT (Address family not supported by protocol)
lua: (command line):1: socket:accept: Address family not supported by protocol
stack traceback:
	[C]: in function 'error'
	/tmp/test/share/lua/5.3/cqueues/socket.lua:90: in function </tmp/test/share/lua/5.3/cqueues/socket.lua:75>
	(...tail calls...)
	/tmp/test/share/lua/5.3/cqueues/socket.lua:231: in method 'accept'
	(command line):1: in main chunk
	[C]: in ?
+++ exited with 1 +++
$ make clean && rm -fr /tmp/test && make install5.3 prefix=/tmp/test CFLAGS=-O0
...
$ LUA_PATH='/tmp/test/share/lua/5.3/?.lua;;' LUA_CPATH='/tmp/test/lib/lua/5.3/?.so' strace -e network lua -e 's=require("cqueues.socket"); print(s.listen("127.0.0.1", 4000):accept())'
socket(AF_INET, SOCK_STREAM|SOCK_CLOEXEC, IPPROTO_IP) = 3
setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
setsockopt(3, SOL_SOCKET, SO_REUSEPORT, [0], 4) = 0
setsockopt(3, SOL_TCP, TCP_NODELAY, [0], 4) = 0
setsockopt(3, SOL_TCP, TCP_CORK, [0], 4) = 0
setsockopt(3, SOL_SOCKET, SO_OOBINLINE, [0], 4) = 0
getsockopt(3, SOL_SOCKET, SO_DOMAIN, [2], [4]) = 0
getsockopt(3, SOL_SOCKET, SO_TYPE, [1], [4]) = 0
getsockopt(3, SOL_SOCKET, SO_PROTOCOL, [6], [4]) = 0
getsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], [4]) = 0
getsockopt(3, SOL_SOCKET, SO_REUSEPORT, [0], [4]) = 0
getsockopt(3, SOL_SOCKET, SO_BROADCAST, [0], [4]) = 0
getsockopt(3, SOL_TCP, TCP_NODELAY, [0], [4]) = 0
getsockopt(3, SOL_TCP, TCP_CORK, [0], [4]) = 0
getsockopt(3, SOL_IPV6, IPV6_V6ONLY, 0x7ffd277da918, 0x7ffd277da91c) = -1 EOPNOTSUPP (Operation not supported)
getsockopt(3, SOL_SOCKET, SO_OOBINLINE, [0], [4]) = 0
bind(3, {sa_family=AF_INET, sin_port=htons(4000), sin_addr=inet_addr("127.0.0.1")}, 16) = 0
listen(3, 128)                          = 0
accept4(3, NULL, NULL, SOCK_CLOEXEC)    = -1 EAGAIN (Resource temporarily unavailable)

Rolling back to gcc 6.3.1 (the only previous version in have in my package cache) or compiling with clang both produces a working binary. Not sure yet if it is a compiler bug or an undefined behaviour lying somewhere that GCC now optimizes differently.

@daurnimator
Copy link
Collaborator

daurnimator commented Jun 18, 2017

@jdesgats ah ha! thankyou for discovering that. I've managed to replicate locally now.

The issue seems to be around dns_ai_setent and the aliasing via saddr. Using -fno-strict-aliasing doesn't seem to fix anything :(

@daurnimator
Copy link
Collaborator

This issue affects anyone using GCC 7, which is becoming more and more common @wahern could you please look at my proposed fix in #187?

@hoelzro
Copy link

hoelzro commented Sep 21, 2017

I just ran into this myself - is the recommendation to install the code under #187 to get things working again until there's a release?

@daurnimator
Copy link
Collaborator

daurnimator commented Sep 22, 2017

Yes. I've gotten permission (via email) from wahern to merge and make a release myself. Just haven't had time yet. I also wanted to fix compiling with luajit 2.1 beta, the best route to which was bringing in lua-compat-5.3, however I need @siffiejoe to cut a release there (as I need some of the code on their master) -> but I think that's blocked on lunarmodules/lua-compat-5.3#36

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants