Skip to content

perf(server): bound the audio request queue and add a per-request timeout #373

Closed

Description

@inureyes

Problem / Background

The OpenAI audio endpoints (speech-to-text landed in #365; text-to-speech is upcoming in #366) dispatch work to a single dedicated AudioWorker thread over an unbounded mpsc::channel (src/server/audio_worker.rs). There is no admission bound and no per-request timeout on the audio path: can_accept_request() (src/server/state.rs, around line 513) gates only on the generation batch queue depth, which the audio path never increments, so it is effectively always true for audio requests.

The PR #371 security review classified the following as MEDIUM under load:

  1. Head-of-line blocking: all audio requests serialize through one worker thread, so a single slow or large clip stalls the whole audio queue.
  2. Unbounded memory growth: each queued command holds up to the 25 MiB per-request audio payload, and nothing caps the number of concurrent in-flight requests, so a burst can grow memory without bound.

Neither is a crash (the per-request resample/alloc bounds from #365 cap a single request), but both are availability/throughput risks on the network-facing path.

Proposed Solution

  • Switch the AudioWorker channel to a bounded mpsc::sync_channel(N) and use try_send, mapping a full queue to the existing 503 "all slots are busy" response path (reuse the server's admission/error envelope rather than inventing a new one).
  • Add a per-request reply timeout so a stuck or pathologically slow request frees its blocking thread and returns a structured error instead of hanging.
  • Make the queue bound and timeout configurable via the server config, with sensible defaults.
  • This lives in the shared AudioWorker, so it covers both the STT path and the TTS path (feat(models): TTS model + vocoder for text-to-speech (/v1/audio/speech) #366).

Acceptance Criteria

  • The audio queue is bounded; when full, new audio requests get a structured 503 through the real server flow (unit/integration test).
  • A per-request timeout returns a structured error and releases the blocking thread (test).
  • Bound and timeout are configurable with documented defaults.
  • Integrated into the live audio request path (not a standalone helper).
  • cargo test, cargo clippy --all-targets -- -D warnings, cargo fmt --check clean.

Technical Considerations

Surfaced by the security review of PR #371 (merged). Anchors: src/server/audio_worker.rs, src/server/state.rs (can_accept_request). Related epic: #363.

Activity

  1. added
    type:enhancement
    area:inference
    priority:medium
    status:ready
    status:in-progress
    status:review
    status:done
    and removed
    status:ready
    status:in-progress
    status:review
    on Jun 19, 2026
  2. added this to the 0.3 milestone on Jun 21, 2026
  3. self-assigned this
    on Aug 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:inferencepriority:mediumstatus:donetype:enhancement

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions