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

net: SO_REUSEADDR, PORT wild use for active open socket breaks websocket app on openbsd #2830

Closed
mikioh opened this issue Feb 2, 2012 · 4 comments
Milestone

Comments

@mikioh
Copy link
Contributor

mikioh commented Feb 2, 2012

-- 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.
@mikioh
Copy link
Contributor Author

mikioh commented Feb 2, 2012

Comment 1:

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.

@mikioh
Copy link
Contributor Author

mikioh commented Feb 4, 2012

Comment 2:

http://tools.ietf.org/html/rfc6056

@mikioh
Copy link
Contributor Author

mikioh commented Feb 9, 2012

Comment 3:

Labels changed: added priority-go1, removed priority-triage.

@mikioh
Copy link
Contributor Author

mikioh commented Feb 11, 2012

Comment 4:

This issue was closed by revision 0e3514e.

Status changed to Fixed.

@rsc rsc added this to the Go1 milestone Apr 10, 2015
@rsc rsc removed the priority-go1 label Apr 10, 2015
@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants