You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-- from code review 5574063: net: disable SO_REUSEADDR and SO_REUSEPORT on openbsd
(issue #5574063) on golang-dev
Sorry, I should have been more specific here. The problem is not due
to use of SO_REUSEADDR on the listening socket - the issue is that we
are setting it on all sockets. As a result, the client performs a
connect() which results in the allocation of a randomised port number
- since SO_REUSEADDR/SO_REUSEPORT are enabled the port number is
permitted to already be in use and the normal duplication checks are
not performed. We then attempt to establish a TCP connection using
this already in use port number, which fails:
19425 test.out CALL socket(PF_INET,SOCK_STREAM,IPPROTO_IP)
19425 test.out RET socket 10/0xa
19425 test.out CALL fcntl(0xa,F_SETFD,FD_CLOEXEC)
19425 test.out RET fcntl 0
19425 test.out CALL setsockopt(0xa,SOL_SOCKET,SO_REUSEADDR,0xf84019ea00,0x4)
19425 test.out RET setsockopt 0
19425 test.out CALL setsockopt(0xa,SOL_SOCKET,SO_REUSEPORT,0xf84019ea08,0x4)
19425 test.out RET setsockopt 0
19425 test.out CALL setsockopt(0xa,SOL_SOCKET,SO_BROADCAST,0xf84019ea10,0x4)
19425 test.out RET setsockopt 0
19425 test.out CALL fcntl(0xa,F_GETFL,0)
19425 test.out RET fcntl 2
19425 test.out CALL fcntl(0xa,F_SETFL,0x6<O_RDWR|O_NONBLOCK>)
19425 test.out RET fcntl 0
19425 test.out CALL connect(0xa,0xf840186768,0x10)
19425 test.out STRU struct sockaddr { AF_INET, 127.0.0.1:43658 }
19425 test.out RET connect -1 errno 48 Address already in use
The other (and probably better) solution is to only set
SO_REUSEADDR/SO_REUSEPORT on sockets that will be listening, probably
via the addition of a func setDefaultListenSockopts(fd *netFD) that
would be called from ListenTCP() et al.
The text was updated successfully, but these errors were encountered:
I'm a bit surprised that network stack in openbsd behaves in such
different ways. IIRC, SO_REUSEADDR, PORT options never affect
active open side socket on freebsd, darwin and perhaps linux.
The text was updated successfully, but these errors were encountered: