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

Aperta
#702 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
1-2 giorni
Idoneità per principianti
35/100
Tipo di issue
Funzionalità
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Python
Stelle
57
Fork
30
Merge medio
3h 14m
PR unite (30g)
56

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di OceanDataTools/openrvdas

Tutte le issue di OceanDataTools/openrvdas

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.