MacOS test test_sync_connect_hook_rejected_fails can hang

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

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
72/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
rust

Research direction

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.

Written by the indexing model from the issue text.

Description

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.

Dominant language
Rust
Stars
374
Forks
64
Avg merge
3d 5h
Merged PRs (30d)
6

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

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

All issues in containerd/ttrpc-rust

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.