Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { AddEventResult, EventBuffer, EventBufferType, RecordingEvent } fro
import { debug } from '../util/logger';
import { EventBufferArray } from './EventBufferArray';
import { EventBufferCompressionWorker } from './EventBufferCompressionWorker';
import { WorkerDestroyedError } from './error';

/**
* This proxy will try to use the compression worker, and fall back to use the simple buffer if an error occurs there.
Expand Down Expand Up @@ -130,6 +131,12 @@ export class EventBufferProxy implements EventBuffer {
// Can now clear fallback buffer as it's no longer necessary
this._fallback.clear();
} catch (error) {
// If the worker was intentionally destroyed (e.g. on session expiry) while
// events were still being compressed, silently ignore the rejection — it is
// expected behaviour and not worth reporting to Sentry.
if (error instanceof WorkerDestroyedError) {
return;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix PR missing regression tests

Medium Severity

This is a fix PR, but the diff adds no unit, integration, or E2E test covering the regression. Per the Testing Conventions in the PR review guidelines (flagged because it was mentioned in the rules file), a fix should include a test that fails without the change and passes with it — for example, asserting that destroying the worker during _switchToCompressionWorker is silently ignored and does not go through debug.exception.

Additional Locations (2)
Fix in Cursor Fix in Web

Triggered by project rule: PR Review Guidelines for Cursor Bot

Reviewed by Cursor Bugbot for commit 726af61. Configure here.

DEBUG_BUILD && debug.exception(error, 'Failed to add events when switching buffers.');
}
}
Expand Down
3 changes: 2 additions & 1 deletion packages/replay-internal/src/eventBuffer/WorkerHandler.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { DEBUG_BUILD } from '../debug-build';
import type { WorkerRequest, WorkerResponse } from '../types';
import { debug } from '../util/logger';
import { WorkerDestroyedError } from './error';

interface PendingRequest {
method: WorkerRequest['method'];
Expand Down Expand Up @@ -75,7 +76,7 @@ export class WorkerHandler {
public destroy(): void {
DEBUG_BUILD && debug.log('Destroying compression worker');
this._worker.removeEventListener('message', this._onMessage);
this._pending.forEach(pending => pending.reject(new Error('Worker destroyed')));
this._pending.forEach(pending => pending.reject(new WorkerDestroyedError()));
this._pending.clear();
this._worker.terminate();
}
Expand Down
7 changes: 7 additions & 0 deletions packages/replay-internal/src/eventBuffer/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,10 @@ export class EventBufferSizeExceededError extends Error {
super(`Event buffer exceeded maximum size of ${REPLAY_MAX_EVENT_BUFFER_SIZE}.`);
}
}

/** This error indicates that the compression worker was intentionally destroyed (e.g. on session expiry). */
export class WorkerDestroyedError extends Error {
public constructor() {
super('Worker destroyed');
}
}
Loading