Skip to content
Draft
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
16 changes: 10 additions & 6 deletions packages/cloudflare/src/transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,16 @@ export class IsolatedPromiseBuffer {

const drainController = new AbortController();
this.drainSignal = drainController.signal;
let tasks: PromiseLike<TransportMakeRequestResponse>[];
try {
tasks = oldTaskProducers.map(taskProducer => taskProducer());
} finally {
this.drainSignal = undefined;
}
const tasks = oldTaskProducers.map(taskProducer => {
// A request that throws synchronously, such as a custom `fetch`, must not stop the other requests
// or throw into the caller.
try {
return taskProducer();
} catch (error) {
return Promise.reject(error);
}
});
this.drainSignal = undefined;

return new Promise(resolve => {
const timer = setTimeout(() => {
Expand Down
18 changes: 17 additions & 1 deletion packages/cloudflare/test/transport.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { EventEnvelope, EventItem } from '@sentry/core';
import type { EventEnvelope, EventItem, TransportMakeRequestResponse } from '@sentry/core';
import { createEnvelope, SENTRY_BUFFER_FULL_ERROR, serializeEnvelope } from '@sentry/core';
import { afterAll, describe, expect, it, vi } from 'vitest';
import type { CloudflareTransportOptions } from '../src/transport';
Expand Down Expand Up @@ -236,6 +236,22 @@ describe('IsolatedPromiseBuffer', () => {
expect(task2).toHaveBeenCalled();
});

it('runs the other tasks of a drain when one task throws synchronously', async () => {
const ipb = new IsolatedPromiseBuffer();

const task1 = vi.fn((): Promise<TransportMakeRequestResponse> => {
throw new Error('foo');
});
const task2 = vi.fn(() => Promise.resolve({}));

await ipb.add(task1);
await ipb.add(task2);

await expect(ipb.drain()).resolves.toEqual(true);

expect(task2).toHaveBeenCalled();
});

it('should allow for a custom fetch function to be passed in', async () => {
const customFetch = vi.fn(async () => {
return {
Expand Down
Loading