Test isolation: ports are reserved per process, so parallel ctest jobs can be handed the same port

Aperta
#1,316 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
45/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
c, python
Ambito
devtools, testing

Direzione di ricerca

Read tests/apps/isolate.py, especially freePort(), _pickPort() and _portFree(), then trace how the selected port reaches the Apache or broker startup. Check how ctest -j launches the apps_* tests and whether the service can retain a reserved socket. Done means concurrent tests cannot claim the same port and startup failures identify the service and port.

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

Descrizione

bug

tests/apps/isolate.py hands out ports with a process-local reservation set, so two
concurrent ctest jobs can be given the same port.

Mechanism. freePort() (tests/apps/isolate.py:154-163) binds a socket to
("127.0.0.1", 0), reads the port the OS offered, closes the socket, and then
only checks the number against _handedOut, a set that lives in the current Python
process:

with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
    sock.bind(("127.0.0.1", 0))
    port = sock.getsockname()[1]
if port not in _handedOut:
    _handedOut.add(port)
    return port

Between the close and the moment the per-user Apache or the broker actually listens,
the port is unowned. Each apps_* ctest test is its own process with its own empty
_handedOut, so under ctest -j two tests can be offered the same number by the OS
and both proceed. _pickPort() (isolate.py:172-186) probes with _portFree() only
for a port given explicitly in the environment; the port that freePort() returns is
not probed again before the service is started.

Consequence. Not a clean "address already in use". The loser is the service that
starts second: the data server early-exits because something is already listening and
the test then talks to the other test's document root, or the broker fails to come up
and the app under test reports a messaging failure. The log shows an assertion failure
in the application, with no line naming a port, which is exactly the class of false
failure isolate.py's own module docstring (isolate.py:1-12) says it exists to
prevent -- it prevents overlap with a developer's live session, not overlap between
two tests of the same run.

Suggested fix: hold the bound socket open until the service has been handed the port
(bind with SO_REUSEADDR off and pass the fd or close it immediately before exec), or
re-probe with _portFree() and retry when the service fails to bind, and have the
failure message name the port and the service.

Not reproduced: this is read from the code. No run has been traced to a port
collision; under ctest -j the symptom would be an intermittent application-level
failure rather than anything that names a port, so an occurrence would not currently
be recognisable from the log.

Lingua principale
C
Stelle
10
Fork
8
Merge medio
6h 32m
PR unite (30g)
1

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

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 FriendsofECCE/ECCE

Tutte le issue di FriendsofECCE/ECCE

Issue simili

Altre issue su C

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.