Skip to content

Commit 3c827a8

Browse files
committed
don't do anything if already paused
1 parent 63eff69 commit 3c827a8

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

packages/replay/src/replay.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,10 @@ export class ReplayContainer implements ReplayContainerInterface {
275275
* not as thorough of a shutdown as `stop()`.
276276
*/
277277
public pause(): void {
278+
console.log('I was called');
279+
280+
console.trace();
281+
278282
this._isPaused = true;
279283
try {
280284
if (this._stopRecording) {
@@ -1093,6 +1097,12 @@ export class ReplayContainer implements ReplayContainerInterface {
10931097
* Pauses the replay and resumes it after the rate-limit duration is over.
10941098
*/
10951099
private _handleRateLimit(): void {
1100+
// in case recording is already paused, we don't need to do anything, as we might have already paused because of a
1101+
// rate limit
1102+
if (this.isPaused()) {
1103+
return;
1104+
}
1105+
10961106
const rateLimitEnd = disabledUntil(this._rateLimits, 'replay');
10971107
const rateLimitDuration = rateLimitEnd - Date.now();
10981108

packages/replay/test/integration/rateLimiting.test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,4 +259,38 @@ describe('Integration | rate-limiting behaviour', () => {
259259
// events array should be empty
260260
expect(replay.eventBuffer?.pendingLength).toBe(0);
261261
});
262+
263+
it("doesn't do anything, if a rate limit is hit and recording is already paused", async () => {
264+
let paused = false;
265+
expect(replay.session?.segmentId).toBe(0);
266+
jest.spyOn(replay, 'isPaused').mockImplementation(() => {
267+
return paused;
268+
});
269+
jest.spyOn(replay, 'pause');
270+
jest.spyOn(replay, 'resume');
271+
// @ts-ignore private API
272+
jest.spyOn(replay, '_handleRateLimit');
273+
274+
const TEST_EVENT = { data: {}, timestamp: BASE_TIMESTAMP, type: 2 };
275+
276+
mockTransportSend.mockImplementationOnce(() => {
277+
return Promise.resolve({ statusCode: 429 });
278+
});
279+
280+
mockRecord._emitter(TEST_EVENT);
281+
paused = true;
282+
283+
// T = base + 5
284+
await advanceTimers(DEFAULT_FLUSH_MIN_DELAY);
285+
286+
expect(mockRecord.takeFullSnapshot).not.toHaveBeenCalled();
287+
expect(mockTransportSend).toHaveBeenCalledTimes(1);
288+
289+
expect(replay).toHaveLastSentReplay({ events: JSON.stringify([TEST_EVENT]) });
290+
291+
expect(replay['_handleRateLimit']).toHaveBeenCalledTimes(1);
292+
expect(replay.resume).not.toHaveBeenCalled();
293+
expect(replay.isPaused).toHaveBeenCalledTimes(2);
294+
expect(replay.pause).not.toHaveBeenCalled();
295+
});
262296
});

0 commit comments

Comments
 (0)