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
Use a single socket for InterfaceChoice.Default #331
Use a single socket for InterfaceChoice.Default #331
Conversation
@jjlawren Can you give this a shot with |
Verified .All still works
12 = |
and .Default 12 = |
98722b5
to
6f50602
Compare
Ran some basic tests against this branch. Everything seems to be working as I'd expect it to with far less traffic. |
I've got it running on 4 systems and all the buffer errors no longer happen :) |
I would like to give this a try with home assistant. Could you give me some directions on how to get this running within hass? |
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 swear one of these days I need to make the logic that choses, creates and configures sockets into a testable unit, sometimes I can't wrap my head around this logic anymore.
Can you update the commit message with some details and motivation behind this? I'd like those to be readily available through the commit history rather than needed to be found on GitHub.
Looks good otherwise. :)
6f50602
to
921d644
Compare
Retesting.. diff --git a/zeroconf/__init__.py b/zeroconf/__init__.py
index 9eeaef5..e21c3e8 100644
--- a/zeroconf/__init__.py
+++ b/zeroconf/__init__.py
@@ -2500,7 +2500,6 @@ class Zeroconf(QuietLogger):
# hook for threads
self._GLOBAL_DONE = False
self.unicast = unicast
- self.interfaces = interfaces
if apple_p2p and not platform.system() == 'Darwin':
raise RuntimeError('Option `apple_p2p` is not supported on non-Apple platforms.')
@@ -2509,6 +2508,7 @@ class Zeroconf(QuietLogger):
interfaces, unicast, ip_version, apple_p2p=apple_p2p
)
log.debug('Listen socket %s, respond sockets %s', self._listen_socket, self._respond_sockets)
+ self.multi_socket = unicast or interfaces is not InterfaceChoice.Default
self.listeners = [] # type: List[RecordUpdateListener]
self.browsers = {} # type: Dict[ServiceListener, ServiceBrowser]
@@ -2528,7 +2528,7 @@ class Zeroconf(QuietLogger):
self.listener = Listener(self)
if not unicast:
self.engine.add_reader(self.listener, cast(socket.socket, self._listen_socket))
- if unicast or interfaces is not InterfaceChoice.Default:
+ if self.multi_socket:
for s in self._respond_sockets:
self.engine.add_reader(self.listener, s)
self.reaper = Reaper(self)
@@ -2994,7 +2994,7 @@ class Zeroconf(QuietLogger):
if not self.unicast:
self.engine.del_reader(cast(socket.socket, self._listen_socket))
cast(socket.socket, self._listen_socket).close()
- if self.unicast or self.interfaces is not InterfaceChoice.Default:
+ if self.multi_socket:
for s in self._respond_sockets:
self.engine.del_reader(s)
self.engine.join() |
Sadly thats not explicit enough since it needs to pickup the unicast cast. |
921d644
to
280be4a
Compare
When using multiple sockets with multi-cast, the outgoing socket's responses could be read back on the incoming socket, which leads to duplicate processing and could fill up the incoming buffer before it could be processed. This behavior manifested with error similar to `OSError: [Errno 105] No buffer space available` By using a single socket with InterfaceChoice.Default we avoid this case.
280be4a
to
1ede182
Compare
Retested Working as expected |
Nice! |
Thanks, would you mind pushing a release so we can merge home-assistant/core#48302 ? |
Oh yeah, sure. There's an issue with the typing that I haven't spotted before merging, would you mind having a look?
(from https://travis-ci.org/github/jstasiak/python-zeroconf/jobs/764291256) |
Looking.. I think it just needs to be casted |
Also I can open a PR to switch to GH actions if you like since travis is shutting down .org |
Oh, I'll take care of that in a moment, I have a template for that already, but thank you for the offer. |
@bdraco Released in 0.29.0! |
Thank you 🙏🏻 |
Fixes a regression caused by refactoring error in python-zeroconf#331
Fixes a regression caused by refactoring error in python-zeroconf#331
Fixes #330
When using multiple sockets with multi-cast, the outgoing
socket's responses could be read back on the incoming socket,
which leads to duplicate processing and could fill up the
incoming buffer before it could be processed.
This behavior manifested with error similar to
OSError: [Errno 105] No buffer space available
By using a single socket with InterfaceChoice.Default
we avoid this case.