Discord API · error code

Discord error 4009: Session timed out

RetryableGateway close codes (4000-4014)

Last verified against Discord Developer Docs - Opcodes and status codes

What Discord returns
Your session timed out. Reconnect and start a new one.

What error 4009 means

Discord stopped hearing from your client for too long and closed the session. The gateway expects a Heartbeat (op 1) at the interval sent in Hello (heartbeat_interval, typically around 41.25 seconds); it acknowledges each one with Heartbeat ACK (op 11). If heartbeats stop arriving, or the connection goes idle in a way that makes the session stale, Discord closes it with 4009. The session cannot be resumed; you need a new Identify.

On the client side, the most common cause is a blocked event loop. Node.js, Python asyncio and similar runtimes run the heartbeat timer on the same loop as your handlers; a synchronous database call, a CPU-heavy computation, a giant JSON parse or a blocking HTTP request delays the heartbeat past the deadline. Many libraries also detect the missing ACK and proactively close with their own code; either way, the root cause is the same. The second cause is the host sleeping (laptop lid, container pause) or losing network for a long period.

What it looks like

// WebSocket close frame
code: 4009
reason: "Session timed out."

Why it happens

  • Event loop blocked by synchronous work so heartbeats are sent late
  • Host suspended, paused, or without network for longer than the heartbeat window
  • CPU starvation on an overloaded or undersized instance
  • Custom client not sending heartbeats at the required interval

How to fix Discord error 4009

  1. 1Reconnect and identify (automatic in libraries)
  2. 2Profile for long synchronous operations and move them off the main loop (worker threads, async drivers, separate process)
  3. 3Watch your library's heartbeat latency metric (ws.ping / latency); if it climbs before disconnects, the loop is stalling
  4. 4Size the host for the workload and avoid running CPU-heavy jobs in the bot process
  5. 5For custom clients, send heartbeats on a dedicated timer and handle missed ACKs by reconnecting

How to stop it recurring

Keep the bot process dedicated to event handling and push heavy work elsewhere. Alert on heartbeat latency spikes, not just on disconnects, so you catch the stall before Discord does.

Session timeouts are usually your process's health telling on itself: late heartbeats today are dropped events tomorrow. Watch heartbeat latency as a first-class metric. The heartbeat interval contract is on the Discord limits page, and a bot that times out repeatedly on a healthy host should be profiled per the checklist in Discord bot not responding.

Official reference: Discord Developer Docs - Opcodes and status codes. See all Discord error codes or the Discord limits and quotas.

Related codes

Error 4009 - quick answers

What does Discord error 4009 mean?

Discord stopped hearing from your client for too long and closed the session. The gateway expects a Heartbeat (op 1) at the interval sent in Hello ( heartbeat_interval , typically around 41.25 seconds); it acknowledges each one with Heartbeat ACK (op 11). If heartbeats stop arriving, or the connection goes idle in a way that makes the session stale, Discord closes it with 4009.

How do I fix Discord error 4009?

1. Reconnect and identify (automatic in libraries) 2. Profile for long synchronous operations and move them off the main loop (worker threads, async drivers, separate process) 3. Watch your library's heartbeat latency metric (ws.ping / latency); if it climbs before disconnects, the loop is stalling 4. Size the host for the workload and avoid running CPU-heavy jobs in the bot process 5. For custom clients, send heartbeats on a dedicated timer and handle missed ACKs by…

Can I retry after error 4009?

Yes - this is a retryable condition. Back off (start around one second and double on each attempt, with jitter) and watch for a retry-after hint from the platform before resending.

Stop debugging Discord by hand

Connect the channel through Conferbot: tokens, webhooks and retries are handled, failures show as readable status.