listen --udp can't share a port with a running logger (reuseport)

Open
#702 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Active
Tech stack
python

Research direction

Start with listen.py and how it constructs UDPReader; then inspect parse_data_logger_template.yaml, udp_logger_template.yaml, and the existing UDPReader reuse options. Confirm Linux unicast behavior before documenting the flag, since reuseport can divert data from the running logger. Done means the opt-in works in both templates, the listen help warns about unicast, and the documented behavior is verified.

Written by the indexing model from the issue text.

Description

Request

Let listen --udp snoop on a UDP port that a running logger (typically parse_data) already has open, so the docs don't have to tell users to switch parse_data off first.

UDPReader already supports reuseaddr / reuseport, but there are two gaps:

  1. listen --udp can't turn them on (listen.py builds UDPReader(source, port, encoding=encoding)).
  2. A second socket can bind only if the socket already holding the port also set the option, and no shipped template sets it (parse_data_logger_template.yaml, udp_logger_template.yaml). So a listen flag alone would never be enough.

Caveat: works for broadcast and multicast, not unicast

Whether both readers see the data depends on how the packets are addressed, not on OpenRVDAS.

Tested on macOS (Darwin 25.6), using UDPReader._open_socket() for both sockets: 20 datagrams sent, first socket bound first (standing in for parse_data), second standing in for listen --udp.

Destination Options on both sockets First Second
unicast to host IP reuseport 20 0
unicast to host IP, 4 senders reuseport 20 0
unicast to 127.0.0.1 reuseport 20 0
subnet broadcast reuseport 20 20
255.255.255.255 reuseport 20 20
any reuseaddr only second bind fails: [Errno 48] Address already in use
any reuseaddr + reuseport same as reuseport alone
any option on only one of the two second bind fails
  • Broadcast (and multicast): every socket bound to the port gets its own copy. Both readers see everything. UDPWriter broadcasts by default when no destination is given, and many instruments broadcast, so this is the common case.
  • Unicast: each datagram goes to only one socket. On macOS that was always the first-bound socket, so the snooper got nothing but did no harm. Linux is untested here. There, SO_REUSEPORT spreads unicast datagrams across sockets by a hash of the sender's address and port, so a single instrument's data would all go to one socket. If that's the snooper, parse_data silently stops getting data. That is worse than the current "address already in use" error. (On Linux both processes also need the same effective UID.)

Possible implementation

  • Add a --udp_reuseport flag to listen that sets reuseport=True on its UDPReaders. The help text should warn that with unicast sources the snooper may take data from the running logger.
  • Add an opt-in template variable (e.g. <<udp_reuseport|false>>) to parse_data_logger_template.yaml and udp_logger_template.yaml, so ships with broadcast feeds can turn it on. It should default to false so existing cruise definitions behave the same.
  • Confirm the Linux unicast behavior before documenting it.

Until then, the docs' advice to switch parse_data off before snooping is the safe option whatever the addressing.

Dominant language
Python
Stars
57
Forks
30
Avg merge
3h 14m
Merged PRs (30d)
56

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from OceanDataTools/openrvdas

All issues in OceanDataTools/openrvdas

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.