8000 Logging: a stalled log consumer stalls Nix, with no bound and no signal · Issue #42 · nixidae/nixidae · GitHub
[go: up one dir, main page]

Skip to content

Logging: a stalled log consumer stalls Nix, with no bound and no signal #42

Closed

Description

@Lillecarl

The log path and Nix's forward progress share fate. A caller who blocks their
own event loop stops the evaluation.

The chain, measured

The back-pressure is not one buffer. It is four, linked:

  1. LogCollector.callback (logging.py:90) does a blocking sync_q.put on a
    queue of 10 000. The C++ logger calls it on the Nix thread.
  2. WorkerServiceHandler.subscribe_logs (_worker.py:445) consumes
    collector.stream() and yields each event straight onto the gRPC
    response. Each yield becomes grpclib.server.Stream.send_message, which
    awaits the HTTP/2 flow-control window. Verified in the grpclib source.
  3. The client's _forward_worker_logs (_pool.py:412) reads that stream and
    calls CallbackBus.emit, which is synchronous and never blocks. So the
    client stops reading only when its event loop stops running.
  4. LogCapture.events (logging.py:256) is an unbounded list, and
    WorkerClient.log_stream (_pool.py:390) opens its memory object stream
    with max_buffer_size=math.inf. Neither has a cap.

Hops 1 and 2 push back, and the caller's event loop is the last consumer. An
event loop is not a real-time consumer, and Nix must not depend on one.

Two further defects, from the same reading

  • A lost request_finalized marker is a permanent hang.
    LogCapture.__aexit__ (logging.py:320) awaits wait() inside
    anyio.CancelScope(shield=True) with no bound. One missing marker parks
    that await for the life of the process, and a cancellation cannot reach it.
    The path already exists: WorkerClient._teardown cancels _log_task after
    _LOG_DRAIN_TIMEOUT_SECONDS while the worker still emits.
  • log_stream's buffer is math.inf. A caller who iterates it slowly
    grows the client process without limit. The same defect as LogCapture,
    one layer down.

The rule to write down

A log event may be lost. Nix's progress may not be delayed. Exactly one hop
in each process is lossy, it sits at the process boundary, and every hop
above it is guaranteed to drain. A control event is never lost.

A control event is a request_finalized marker or the stream sentinel. A
log line is diagnostic; a marker is protocol.

hop rule
Nix thread → collector never blocks. put_nowait; on a full queue, drop and count
collector → relay task always drains. The relay's only job is to move events
relay → outbox lossy. Bounded; discard the oldest log line, never a control event
outbox → wire may park on flow control, which is correct: it backs up into the outbox only
wire → client bus already always drains
bus → LogCapture bounded, discard the oldest

The oldest, not the newest, at every cap: nanopynix_helpers/build.py:78 and
ekn/src/ekn/eval.py:356 both scan a capture for the fixed-output hash
mismatch Nix prints next to the failure, so the end of a log is the part worth
keeping.

Scope

  • LogCollector.callback never blocks. request_finalized and the sentinel
    take the place of the oldest queued event rather than joining the drop
    count. stats() reports dropped, which the SIGUSR1 dump already prints.
  • A new LogOutbox: the worker's bounded hand-off from the relay to
    SubscribeLogs. Same policy, one hop on.
  • A relay task, started by worker_service_factory, that drains the collector
    unconditionally.
  • LogCapture gains max_events and wait_timeout, plus truncated,
    dropped_events and unfinalized_request_ids. wait() is bounded and
    records; wait_for_request raises.
  • The loss reaches the caller. A new nix.common.EventsDropped variant in
    the LogEvent oneof says how many events the producer discarded, at the
    point in the stream where it happened. Without it a caller reads a short log
    and cannot tell. Both engines send it, so LogCapture.dropped_events means
    the same thing on each.

Acceptance criteria

  • An operation that emits more than maxsize events into a consumer that
    never drains completes, and stats()["dropped"] > 0.
  • An evaluation completes while the client's event loop is held closed.
  • A capture whose events were capped reports truncated.
  • A capture that lost events upstream reports dropped_events, on both
    engines.
  • A finalize marker that never arrives ends the block and appears in
    unfinalized_request_ids, instead of hanging.

Finding F11 of CODE_IMPROVEMENT_PLAN.md.

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

    source: nanopynix

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0