Skip to content

saveFailedLogsToStorage has no total cap, allowing localStorage to grow indefinitely #39

@gaetancharlie

Description

@gaetancharlie

Description

The _saveFailedLogsToStorage method in EventLogger.js caps new events per flush to MAX_FAILED_LOGS (500), but does not cap the total accumulated events. This allows localStorage to grow indefinitely when network requests consistently fail.

Steps to Reproduce

  1. Configure environment where Statsig's /v1/rgstr endpoint consistently fails (e.g., ad blocker, corporate firewall)
  2. Use the application normally, triggering gate checks and exposure events
  3. Each failed flush appends up to 500 events to existing stored events
  4. Over time, statsig.failed_logs.* grows to thousands of events

Current Behavior

_saveFailedLogsToStorage(events) {
    while (events.length > MAX_FAILED_LOGS) {  // Only caps NEW events
        events.shift();
    }
    const savedEvents = this._getFailedLogsFromStorage(storageKey);  // No limit
    _setObjectInStorage(storageKey, [...savedEvents, ...events]);    // And keeps growing
}

Expected Behavior

The total accumulated events should be capped, not just new events per flush:

_saveFailedLogsToStorage(events) {
    const savedEvents = this._getFailedLogsFromStorage(storageKey);
    const combined = [...savedEvents, ...events];
    if (combined.length > MAX_FAILED_LOGS) {
        combined.splice(0, combined.length - MAX_FAILED_LOGS);
    }
    _setObjectInStorage(storageKey, combined);
}

Impact

  • localStorage exhaustion: Users can accumulate events until localStorage is full
  • QuotaExceededError: Breaks applications when localStorage limit is reached
  • Performance: Page load attempts to retry thousands of failed events
  • User experience: Application may crash or behave unexpectedly

Environment

  • @statsig/client-core: 3.26.0
  • @statsig/js-client: 3.26.0
  • Browser: Chrome/Firefox/Safari (all affected)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions