[New-bugs-announce] [issue44005] multiple socket bind failure on Mac OS X with SO_REUSEADDR

giangy report at bugs.python.org
Sat May 1 17:16:26 EDT 2021

New submission from giangy <sforzagianluca at gmail.com>:

I am connecting to a server using a multicast UDP socket.

Running two instances of the code below, in two shell windows on the same computer, it works on both Windows 10 and Ubuntu 18.04, but it fails on Mac OS 10.15.7, reporting:

>>> sock.bind(('', MCAST_PORT))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: [Errno 48] Address already in use


import socket 


MCAST_PORT = 10000

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.setsockopt(socket.SOL_IP, socket.IP_MULTICAST_IF, socket.inet_aton(CLIENT_IP))
sock.setsockopt(socket.SOL_IP, socket.IP_ADD_MEMBERSHIP, socket.inet_aton(MCAST_ADDR) + socket.inet_aton(CLIENT_IP))
sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 2)
sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_IF, socket.inet_aton(CLIENT_IP))
sock.bind(('', MCAST_PORT))

components: Library (Lib), macOS
messages: 392641
nosy: ned.deily, ronaldoussoren, sforzagianluca
priority: normal
severity: normal
status: open
title: multiple socket bind failure on Mac OS X with SO_REUSEADDR
type: behavior
versions: Python 3.8

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list