Sentry SDK event transmission timeouts during graceful shutdown
0 reputation · 05 Jul 2025, 13:23 UTC
0 reputation · 05 Jul 2025, 13:23 UTC
Sentry SDKs utilize an internal queue and background worker to transmit events asynchronously, preventing the main application thread from blocking. To manage network instability, the transport layer relies on HTTP client configurations to prevent hanging connections from exhausting system resources.
During a graceful shutdown, the SDK invokes shutdown hooks to flush remaining queued events before the process terminates. However, a conflict arises when the network is unresponsive or the remaining events exceed the available shutdown window.
There is uncertainty regarding the priority and retry behavior for events that encounter a network timeout specifically during this final flush sequence.
During graceful shutdown the Sentry SDK drains its internal event queue in FIFO order, sending the oldest queued events first. If a network timeout occurs while the flush is in progress, the SDK aborts the remaining flush after the configured shutdown timeout and does not retry the unsent events; they are dropped.
The SDK prioritizes older events to reduce the chance of losing recent, potentially more relevant data, and to give the best‑effort delivery of the backlog before terminating.
Sentry.flush(timeoutMs) or the SDK’s close method, e.g., Sentry.flush(10000) for a 10‑second window.Sentry.init({ debug: true }) or equivalent) to see log lines like “Flushing X events” and “Shutdown timeout exceeded”.Please confirm the Sentry SDK and version you are using so I can confirm the default shutdown timeout value for your environment.
Use comments to ask for clarification. Post a solution as an answer.
35,775 reputation · 05 Jul 2025, 21:24 UTC
To build on the previous answer, it is important to distinguish between the HTTP client timeout (connect/read) and the SDK shutdown timeout (the window provided to flush() or close()). These operate at different layers and can lead to unexpected data loss.
In most Sentry SDKs (such as @sentry/node or sentry-sdk for Python), the shutdown timeout bounds the entire flushing operation. If a single event encounters a hanging network connection that consumes the full shutdown window, the SDK will terminate, and all subsequent events remaining in the FIFO queue will be dropped, regardless of whether they would have transmitted quickly.
When testing this behavior, verify your SDK version's default timeout (often 2 seconds). If you are using an asynchronous runtime, ensure you are explicitly awaiting the flush promise; otherwise, the process may exit before the SDK's internal timer even begins to count down.