-
Notifications
You must be signed in to change notification settings - Fork 38
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
MNT: Bind to PORT 0 #543
MNT: Bind to PORT 0 #543
Conversation
The concern mentioned in the article is that if you bind to the port, close the socket and then try binding to the same port again (perhaps in a separate “program”) the port may not still be available. Does that apply here? |
Actually I think there is a deeper problem here. We use this socket to broadcast to multiple interfaces caproto/caproto/threading/client.py Line 459 in a3fb3d5
so there is no single “our address”. I have an unfinished branch I worked on at ICALEPCS that might be helpful. Will push when I’m back to a laptop. |
I don't think so and want to double check with you. |
Gotcha. I don't think so either but wanted to double-check with you! :-D |
I don't think it fixes the issue, but it's the right framework in which to fix the issue. Can you test and see if the bug is still there, to be sure? |
I was trying to say bind socket with I might also totally wrong. |
caproto/threading/client.py
Outdated
@@ -670,7 +672,7 @@ def command_loop(self): | |||
name, cid, *accepted_address, *new_address, | |||
extra={'pv': name, | |||
'their_address': accepted_address, | |||
'our_address': self.udp_sock.getsockname()[:2]}) | |||
'our_address': self.broadcaster.client_address}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This won't work until #544 is merged, right? I don't think client_address
exists yet.
$ git grep client_address
caproto/_commands.py: .. attribute:: client_address
caproto/_commands.py: def __init__(self, client_address='0.0.0.0'):
caproto/_commands.py: ipv4_to_int32(str(client_address)))
caproto/_commands.py: def client_address(self):
caproto/tests/test_serialization.py: 'client_address': [ip],
doc/source/command-line-client.rst: [D 20:00:47.564 _broadcaster:74] 1 of 1 RepeaterRegisterRequest(client_address='0.0.0.0')
doc/source/shark.rst: 1550679067.619182 192.168.86.21:55928->255.255.255.255:5065 RepeaterRegisterRequest(client_address='0.0.0.0')
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean using our_address
here. #544 isn't required.
This fixes the critical Windows bug introduces in v0.4.0. Closes caproto#540 Closes caproto#514 This takes the approach first proposed by @ke-zhang-rd in caproto#543 commit a3fb3d5 and applies it uniformly to all clients. Also, we bind immediately after creating the socket.
Revisiting this, I think your first approach was the right one. Refining that a bit, if we bind right after we create the socket we can avoid getting tangled up in the |
Is there still work to do here now that #551 is in? |
I think not. Please reopen if I am mistaken, @ke-zhang-rd. |
Goal
This PR is trying to solve #540 and #514 related socket error only reported on windows.
Solution
It looks like Linux and Mac will assign
('0.0.0.0', 0)
to socket, if we didn't explicitbind
.bind
argument in this PR is based onTest
This PR solved scenario in those two issues(#540, #514) but may need further tests.