Skip to content

Commit f377d5c

Browse files
authored
fix: make no buffer space available when adding multicast memberships forgiving (#1516)
1 parent 00cd736 commit f377d5c

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

src/zeroconf/_utils/net.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,20 @@ def add_multicast_member(
302302
interface,
303303
)
304304
return False
305+
if _errno == errno.ENOBUFS:
306+
# https://github.com/python-zeroconf/python-zeroconf/issues/1510
307+
if not is_v6 and sys.platform.startswith("linux"):
308+
log.warning(
309+
"No buffer space available when adding %s to multicast group, "
310+
"try increasing `net.ipv4.igmp_max_memberships` to `1024` in sysctl.conf",
311+
interface,
312+
)
313+
else:
314+
log.warning(
315+
"No buffer space available when adding %s to multicast group.",
316+
interface,
317+
)
318+
return False
305319
if _errno == errno.EADDRNOTAVAIL:
306320
log.info(
307321
"Address not available when adding %s to multicast "

tests/utils/test_net.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import errno
66
import socket
7+
import sys
78
import unittest
89
from unittest.mock import MagicMock, Mock, patch
910

@@ -181,7 +182,7 @@ def test_set_mdns_port_socket_options_for_ip_version():
181182
netutils.set_mdns_port_socket_options_for_ip_version(sock, ("",), r.IPVersion.V4Only)
182183

183184

184-
def test_add_multicast_member():
185+
def test_add_multicast_member(caplog: pytest.LogCaptureFixture) -> None:
185186
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
186187
interface = "127.0.0.1"
187188

@@ -221,6 +222,26 @@ def test_add_multicast_member():
221222
with patch("socket.socket.setsockopt"):
222223
assert netutils.add_multicast_member(sock, interface) is True
223224

225+
# Ran out of IGMP memberships is forgiving and logs about igmp_max_memberships on linux
226+
caplog.clear()
227+
with (
228+
patch.object(sys, "platform", "linux"),
229+
patch("socket.socket.setsockopt", side_effect=OSError(errno.ENOBUFS, "No buffer space available")),
230+
):
231+
assert netutils.add_multicast_member(sock, interface) is False
232+
assert "No buffer space available" in caplog.text
233+
assert "net.ipv4.igmp_max_memberships" in caplog.text
234+
235+
# Ran out of IGMP memberships is forgiving and logs
236+
caplog.clear()
237+
with (
238+
patch.object(sys, "platform", "darwin"),
239+
patch("socket.socket.setsockopt", side_effect=OSError(errno.ENOBUFS, "No buffer space available")),
240+
):
241+
assert netutils.add_multicast_member(sock, interface) is False
242+
assert "No buffer space available" in caplog.text
243+
assert "net.ipv4.igmp_max_memberships" not in caplog.text
244+
224245

225246
def test_bind_raises_skips_address():
226247
"""Test bind failing in new_socket returns None on EADDRNOTAVAIL."""

0 commit comments

Comments
 (0)