MacOS test test_sync_connect_hook_rejected_fails can hang

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

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
72/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
rust

Direzione di ricerca

Start in server.rs: read Connection::shutdown (around lines 118-119), the client_handler loop blocked at control_rx.recv() (line 665), and the reader thread's exit paths feeding control_tx_reader. The described fix is to have the reader always send on control_tx_reader when leaving its loop, not only on error paths. Then run the reproduction command from the issue against the test binary for test_sync_connect_hook_rejected_fails to confirm no runs hang under timeout 20.

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

Descrizione

Description of problem

Run multiple instances of the test binary on MacOS at the same time, like this:

BIN=$(cargo test --features sync,security_extension --test hook_integration_sync_unix --no-run 2>&1 \
  | grep -oE 'target/debug/deps/hook_integration_sync_unix-[0-9a-f]+')
seq 1 800 | xargs -P 8 -I{} sh -c \
  "timeout 20 $BIN test_sync_connect_hook_rejected_fails --exact >/dev/null 2>&1; [ \$? -eq 124 ] && echo 'run {} hung'"

This happened in the CI run of PR #314 for example.

Expected result

All tests pass

Actual result

Some tests hang.

Analysis

What the stack trace shows

  • The test thread is stuck in Server::shutdown() → disconnect(), waiting for the reaper thread to finish (server.rs:784).
  • The reaper waits for the connection's client_handler thread.
  • client_handler is blocked forever in control_rx.recv() (server.rs:665).
  • The response thread is still waiting on res_rx, because client_handler still holds res_tx.
  • The reader thread and all method-handler threads have already exited.

Why it deadlocks

This is a race between shutdown() and a connection the server has only just accepted:

  • The client connects. The hook rejects it and the client closes the fd straight away. Unlike the other tests, no request is ever sent, so nothing ensures the server has finished setting up the connection.
  • The listener accepts the connection and spawns client_handler, just as the test calls server.shutdown().
    disconnect() calls Connection::shutdown(), which sets quit = true (server.rs:118-119).
  • The reader thread and the newly started method-handler threads see quit == true at the top of their loops and exit without sending anything on control_tx.
  • client_handler had already checked quit and entered control_rx.recv(). It holds its own control_tx clone, so recv() never returns an error, and nothing else is left to send. It blocks forever.

Possible fix

have the reader thread always send on control_tx_reader when it leaves its loop, not only on its error paths. A send after client_handler has gone fails harmlessly, because control_rx is dropped before the reader is joined. Alternatively, the test could send one request before shutdown() so the connection is fully set up, but that only hides the server bug.

Lingua principale
Rust
Stelle
374
Fork
64
Merge medio
3g 5h
PR unite (30g)
6

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 containerd/ttrpc-rust

Tutte le issue di containerd/ttrpc-rust

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.