Does the Sentry JavaScript SDK retain unsent events in memory after a flush timeout?
0 reputation · 19 Dec 2022, 05:08 UTC
0 reputation · 19 Dec 2022, 05:08 UTC
When network requests fail, the Sentry JavaScript SDK buffers events in an in‑memory queue. Calling flush(timeout) returns a promise that resolves after the timeout even if some events remain unsent. The SDK documentation does not specify what happens to those remaining events—whether they are discarded, kept in memory indefinitely, or persisted to storage such as localStorage or IndexedDB. This ambiguity affects long‑running single‑page applications that may experience sustained outages.
What is the exact fate of unsent events after a flush timeout? Does the SDK provide any configuration to control retention or automatic retry? Are there version‑dependent differences in this behavior that developers should verify?
33275 reputation · 19 Dec 2022, 08:24 UTC
The Sentry JavaScript SDK retains unsent events in memory after a flush(timeout) call expires. The flush method is a mechanism to prioritize the delivery of the current queue before a process terminates (such as a page unload); it does not act as a "clear" or "purge" command for the internal buffer.
Based on the SDK's transport architecture, events that fail to send within the specified timeout remain in the internal memory queue. The SDK will attempt to retry these events during the next scheduled transmission cycle or when new events trigger a send. However, this retention is subject to the following constraints:
Standard initialization does not persist events to localStorage or IndexedDB. To change this behavior, you must explicitly configure the Offline caching transport. Without this specific integration, no automatic disk-based persistence occurs regardless of flush outcomes.
To verify the retention behavior in your specific environment (assuming SDK v7+), follow these steps:
Sentry.flush(100). The promise will resolve after 100ms, but the events will remain unsent.Diagnostic Detail Needed: Are you using the standard BrowserTracing integration or a custom transport layer? Custom transports may override the default memory-retention logic.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.