Skip to content

Worker keeps running after an error on its command channel #1912

Closed

Description

@Shine-neko

What happens

A worker whose command channel is closed by the main process keeps running when the close shows up as an error on the channel rather than a hang-up. In Server::run (lib/src/server.rs), the command channel token is handled like this:

Token(0) => {
    if event.is_error() {
        error!("error reading from command channel");
        continue;
    }
    if event.is_read_closed() || event.is_write_closed() {
        error!("command channel was closed");
        return;
    }
    ...

The error branch only logs and continues. With the channel registered edge-triggered, no further event comes for it, so the worker never leaves its event loop, and a caller joining the worker thread waits forever.

When the close is an error

The command channel is a Unix stream socket. On Linux, when one end is closed while it still holds data it has not read, the other end gets ECONNRESET (EPOLLERR) rather than a plain hang-up. So it is enough for the main process to send a command, not read the worker's answer (for instance after giving up waiting for it), and then close the channel.

Reproduction

With sozu-lib 2.3.2, on Linux:

  1. Start an HTTP worker on a Channel::generate pair and wait for it to answer a Status.
  2. Write a WorkerRequest (Status) on the command end, do not read the answer, wait ~300 ms so it lands.
  3. Drop the command end.

The worker logs error reading from command channel and its thread is still running seconds later, every time. Without step 2 it logs command channel was closed and exits. Sending HardStop before dropping the channel ends it in both cases.

We hit this in Sōzune as an intermittent hang on shutdown (a slow worker had a late answer pending), and now send HardStop to every worker on shutdown.

Suggestion

Treat an error on the command channel like a close, and return, since the main process can no longer drive the worker.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions