Skip to content

Set SO_REUSEPORT on multicast input sockets for Apple platforms#6471

Open
keskinonur wants to merge 1 commit into
eProsima:masterfrom
bilims:bugfix/macos-multicast-reuseport
Open

Set SO_REUSEPORT on multicast input sockets for Apple platforms#6471
keskinonur wants to merge 1 commit into
eProsima:masterfrom
bilims:bugfix/macos-multicast-reuseport

Conversation

@keskinonur

Copy link
Copy Markdown

Description

OpenAndBindInputSocket() sets SO_REUSEPORT on multicast input sockets only for QNX (#272, #350). Apple platforms (macOS/Darwin) have the same BSD requirement: with SO_REUSEADDR alone, the second process on a host that binds the SPDP multicast port gets EADDRINUSE, the failure is swallowed, and that participant never receives discovery multicast — it silently sees an empty domain while unicast ports bind fine.

This PR extends the existing QNX conditional to __APPLE__ in both UDPv4Transport.cpp and UDPv6Transport.cpp.

Linux intentionally unchanged: SO_REUSEPORT on Linux load-balances datagrams across sockets rather than duplicating them, which would break multi-process discovery instead of fixing it.

Fixes #6470

Motivation

Real-world failure: two librealsense processes using an Intel RealSense D555 Ethernet camera on macOS — whichever process binds the multicast port second never discovers the camera. Socket-level repro (no DDS needed) in the linked issue shows EADDRINUSE for the second bind without SO_REUSEPORT and full duplicate delivery to both sockets with it.

Verified on macOS / Apple Silicon with a live D555 (RealSense PoE camera): without this patch a second concurrently-running process never discovers the remote participant; with it, second-process discovery works.

Full disclosure: our downstream stack also serializes near-simultaneous participant creation — a separate, rarer effect noted in #6470 as out of scope; an end-to-end 22/22 dual-process figure we report elsewhere was measured with both measures in place. The socket-level repro in the issue isolates what this patch alone fixes.

Contributor Checklist

  • Commit messages follow the project guidelines + DCO sign-off (Signed-off-by: Onur Keskin <keskinonur@me.com>)
  • The change reduces to a preprocessor-conditional extension of an already-accepted platform fix (Forcing SO_REUSEPORT on QNX systems. [4109] #350); no API/behavior change on non-Apple platforms
  • Tests: existing multicast tests cover the code path on Apple CI runners (none add SO_REUSEPORT-specific coverage; can add a dual-socket unit test if maintainers want one)

Backport

Please consider backporting to maintained 2.x branches (librealsense currently pins v2.10.4 / v2.10.4-realsense). The change is a one-line platform guard extension plus a short comment.

OpenAndBindInputSocket() only enabled SO_REUSEPORT for QNX (eProsima#272, eProsima#350).
On Darwin, SO_REUSEADDR alone is not enough for two processes to share a
UDP multicast port: the second bind fails with EADDRINUSE, the failure is
not surfaced, and that DomainParticipant never receives SPDP multicast.

Extend the existing QNX conditional to __APPLE__ in UDPv4 and UDPv6
transports. Linux intentionally unchanged: SO_REUSEPORT there load-balances
datagrams instead of duplicating delivery.

Signed-off-by: Onur Keskin <onur@bilims.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

macOS: second process on a host cannot receive SPDP multicast — SO_REUSEPORT is set only for QNX

1 participant