Repository navigation
Bind default sources to an ephemeral port so they don't take receivers' unicast - #84
Open
stewartadam wants to merge 1 commit into
Open
stewartadam wants to merge 1 commit into
stewartadam wants to merge 1 commit into
Conversation
SacnSource::new_v4/new_v6 bound 0.0.0.0:5568 with SO_REUSEPORT, the same port and option the receiver uses. On Linux that puts both sockets in one reuseport group and unicast datagrams are spread between them by source port, so a receiver on the same host lost part of its unicast sACN to the source's socket, which is never read. In a local test 15 of 40 unicast packets went missing. The default constructors now bind port 0. with_ip documents the pitfall. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KzaQVPkrkczgX2g7wGkip5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
SacnSource::new_v4,new_v6,with_cid_v4andwith_cid_v6bound the source socket to0.0.0.0:5568(or[::]:5568) withSO_REUSEPORT. The receiver binds the same port with the same option. On Linux that puts both sockets in one reuseport group, and the kernel spreads incoming unicast datagrams across the group by hashing the sender's address and port. The source never reads its socket, so any unicast sACN that hashes to it is silently lost. Multicast is unaffected because it's delivered to every socket.I confirmed this on Linux before changing anything. With a receiver on
127.0.0.1:5568and an idle default source in the same process, the receiver got 25 of 40 unicast packets sent from fresh ephemeral ports. With no source running, it got 40 of 40.Fix
with_ipdocs now warn against bindingACN_SDT_MULTICAST_PORTwhen a receiver may share the host.Callers that pass an explicit address to
with_iporwith_cid_ipkeep exactly what they asked for.Test
Added
test_default_source_does_not_steal_unicasttotests/src_tests.rs. It sends 20 unicast packets from fresh sockets to a receiver while a default source is running. It fails onmain(14 of 20 received in one run) and passes with this change. All oftests/src_tests.rspasses.