logo

Timeout

A timeout is a time limit placed on an operation. If the operation doesn’t finish within that limit, the system cancels it and treats the attempt as a failure. Timeouts prevent your application from waiting indefinitely for a response that may never arrive.

Types of Timeouts

TypeWhat It Limits
Connection timeoutTime to establish a TCP connection
Read timeoutTime to receive a response after connecting
Gateway timeout (504)Time a reverse proxy waits for a backend
Request timeout (408)Time a server waits for the client to finish sending
Task timeoutTime allowed for a background task to complete

Why Timeouts Matter

Without timeouts, a single slow dependency can cascade through your system:

  • Connections pile up, exhausting your connection pool
  • Memory usage grows as pending requests accumulate
  • Upstream callers start timing out too, causing a chain reaction
  • Eventually your entire service becomes unresponsive

Timeouts in AsyncQueue

When creating a task, you can set a timeout for how long AsyncQueue should wait for your callback endpoint to respond:

await aq.tasks.create({
  callbackUrl: 'https://your-app.com/api/generate-report',
  payload: { reportId: 'rpt_123' },
  timeout: 120,    // allow up to 2 minutes
  retries: 2,      // retry if it times out
});

If your endpoint doesn’t respond within the timeout, AsyncQueue marks the attempt as failed and triggers a retry when configured.

Best Practices

  • Always set timeouts on outbound HTTP calls — never let fetch or axios wait forever
  • Set task timeouts based on measured p99 durations — add a buffer but don’t be overly generous
  • Use shorter timeouts for user-facing requests and longer timeouts for background tasks
  • Combine timeouts with retries — a single timeout doesn’t mean permanent failure