Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/zeroconf/_utils/net.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,20 @@ def add_multicast_member(
interface,
)
return False
if _errno == errno.ENOBUFS:
# https://github.com/python-zeroconf/python-zeroconf/issues/1510
if not is_v6 and sys.platform.startswith("linux"):
log.warning(
"No buffer space available when adding %s to multicast group, "
"try increasing `net.ipv4.igmp_max_memberships` to `1024` in sysctl.conf",
interface,
)
else:
log.warning(
"No buffer space available when adding %s to multicast group.",
interface,
)
return False
if _errno == errno.EADDRNOTAVAIL:
log.info(
"Address not available when adding %s to multicast "
Expand Down
23 changes: 22 additions & 1 deletion tests/utils/test_net.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import errno
import socket
import sys
import unittest
from unittest.mock import MagicMock, Mock, patch

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


def test_add_multicast_member():
def test_add_multicast_member(caplog: pytest.LogCaptureFixture) -> None:
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
interface = "127.0.0.1"

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

# Ran out of IGMP memberships is forgiving and logs about igmp_max_memberships on linux
caplog.clear()
with (
patch.object(sys, "platform", "linux"),
patch("socket.socket.setsockopt", side_effect=OSError(errno.ENOBUFS, "No buffer space available")),
):
assert netutils.add_multicast_member(sock, interface) is False
assert "No buffer space available" in caplog.text
assert "net.ipv4.igmp_max_memberships" in caplog.text

# Ran out of IGMP memberships is forgiving and logs
caplog.clear()
with (
patch.object(sys, "platform", "darwin"),
patch("socket.socket.setsockopt", side_effect=OSError(errno.ENOBUFS, "No buffer space available")),
):
assert netutils.add_multicast_member(sock, interface) is False
assert "No buffer space available" in caplog.text
assert "net.ipv4.igmp_max_memberships" not in caplog.text


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