File tree 6 files changed +64
-33
lines changed
6 files changed +64
-33
lines changed Original file line number Diff line number Diff line change @@ -44,13 +44,14 @@ export class BacktraceBrowserRequestHandler implements BacktraceRequestHandler {
44
44
) : Promise < BacktraceReportSubmissionResult < T > > {
45
45
const controller = new AbortController ( ) ;
46
46
const id = setTimeout ( ( ) => controller . abort ( ) , this . _timeout ) ;
47
+ const signal = anySignal ( abortSignal , controller . signal ) ;
47
48
48
49
try {
49
50
const response = await fetch ( submissionUrl , {
50
51
method : 'POST' ,
51
52
body : payload ,
52
53
headers : typeof payload === 'string' ? this . JSON_HEADERS : this . MULTIPART_HEADERS ,
53
- signal : anySignal ( abortSignal , controller . signal ) ,
54
+ signal,
54
55
} ) ;
55
56
56
57
clearInterval ( id ) ;
@@ -84,6 +85,11 @@ export class BacktraceBrowserRequestHandler implements BacktraceRequestHandler {
84
85
}
85
86
86
87
return BacktraceReportSubmissionResult . OnUnknownError ( err . message ) ;
88
+ } finally {
89
+ // Check for backwards compatibility
90
+ if ( 'dispose' in signal && typeof signal . dispose === 'function' ) {
91
+ signal . dispose ( ) ;
92
+ }
87
93
}
88
94
}
89
95
Original file line number Diff line number Diff line change @@ -45,12 +45,14 @@ export class ReactNativeRequestHandler implements BacktraceRequestHandler {
45
45
const controller = new AbortController ( ) ;
46
46
const id = setTimeout ( ( ) => controller . abort ( ) , this . _timeout ) ;
47
47
48
+ const signal = anySignal ( abortSignal , controller . signal ) ;
49
+
48
50
try {
49
51
const response = await fetch ( submissionUrl , {
50
52
method : 'POST' ,
51
53
body : payload ,
52
54
headers : typeof payload === 'string' ? this . JSON_HEADERS : this . MULTIPART_HEADERS ,
53
- signal : anySignal ( abortSignal , controller . signal ) ,
55
+ signal,
54
56
} ) ;
55
57
56
58
clearInterval ( id ) ;
@@ -84,6 +86,11 @@ export class ReactNativeRequestHandler implements BacktraceRequestHandler {
84
86
}
85
87
86
88
return BacktraceReportSubmissionResult . OnUnknownError ( err . message ) ;
89
+ } finally {
90
+ // Check for backwards compatibility
91
+ if ( 'dispose' in signal && typeof signal . dispose === 'function' ) {
92
+ signal . dispose ( ) ;
93
+ }
87
94
}
88
95
}
89
96
Original file line number Diff line number Diff line change @@ -202,12 +202,14 @@ export function createAbortController(): OriginalAbortController {
202
202
}
203
203
}
204
204
205
- export function anySignal ( ...signals : ( OriginalAbortSignal | undefined ) [ ] ) : OriginalAbortSignal {
206
- const controller = createAbortController ( ) ;
205
+ interface DisposableAbortSignal extends OriginalAbortSignal {
206
+ dispose ( ) : void ;
207
+ }
207
208
208
- function onAbort ( ) {
209
- controller . abort ( ) ;
209
+ export function anySignal ( ... signals : ( OriginalAbortSignal | undefined ) [ ] ) : DisposableAbortSignal {
210
+ const controller = createAbortController ( ) ;
210
211
212
+ function cleanup ( ) {
211
213
// Cleanup
212
214
for ( const signal of signals ) {
213
215
if ( signal ) {
@@ -216,6 +218,11 @@ export function anySignal(...signals: (OriginalAbortSignal | undefined)[]): Orig
216
218
}
217
219
}
218
220
221
+ function onAbort ( ) {
222
+ controller . abort ( ) ;
223
+ cleanup ( ) ;
224
+ }
225
+
219
226
for ( const signal of signals ) {
220
227
if ( ! signal ) {
221
228
continue ;
@@ -228,5 +235,6 @@ export function anySignal(...signals: (OriginalAbortSignal | undefined)[]): Orig
228
235
signal . addEventListener ( 'abort' , onAbort ) ;
229
236
}
230
237
231
- return controller . signal ;
238
+ ( controller . signal as DisposableAbortSignal ) . dispose = cleanup ;
239
+ return controller . signal as DisposableAbortSignal ;
232
240
}
Original file line number Diff line number Diff line change @@ -276,34 +276,38 @@ export class BacktraceDatabase implements BacktraceModule {
276
276
const records = [ ...this . _databaseRecordContext . getBucket ( bucketIndex ) ] ;
277
277
const signal = anySignal ( abortSignal , this . _abortController . signal ) ;
278
278
279
- for ( const record of records ) {
280
- if ( ! this . enabled ) {
281
- return ;
282
- }
283
- if ( record . locked ) {
284
- continue ;
285
- }
286
- try {
287
- record . locked = true ;
288
-
289
- const result =
290
- record . type === 'report'
291
- ? await this . _requestHandler . send ( record . data , record . attachments , signal )
292
- : await this . _requestHandler . sendAttachment ( record . rxid , record . attachment , signal ) ;
293
-
294
- if (
295
- result . status === 'Ok' ||
296
- result . status === 'Unsupported' ||
297
- result . status === 'Report skipped'
298
- ) {
299
- this . remove ( record ) ;
279
+ try {
280
+ for ( const record of records ) {
281
+ if ( ! this . enabled ) {
282
+ return ;
283
+ }
284
+ if ( record . locked ) {
300
285
continue ;
301
286
}
302
- this . _databaseRecordContext . increaseBucket ( bucketIndex ) ;
303
- return ;
304
- } finally {
305
- record . locked = false ;
287
+ try {
288
+ record . locked = true ;
289
+
290
+ const result =
291
+ record . type === 'report'
292
+ ? await this . _requestHandler . send ( record . data , record . attachments , signal )
293
+ : await this . _requestHandler . sendAttachment ( record . rxid , record . attachment , signal ) ;
294
+
295
+ if (
296
+ result . status === 'Ok' ||
297
+ result . status === 'Unsupported' ||
298
+ result . status === 'Report skipped'
299
+ ) {
300
+ this . remove ( record ) ;
301
+ continue ;
302
+ }
303
+ this . _databaseRecordContext . increaseBucket ( bucketIndex ) ;
304
+ return ;
305
+ } finally {
306
+ record . locked = false ;
307
+ }
306
308
}
309
+ } finally {
310
+ signal . dispose ( ) ;
307
311
}
308
312
}
309
313
}
Original file line number Diff line number Diff line change @@ -42,7 +42,12 @@ export class MetricsSubmissionQueue<T extends MetricsEvent> implements MetricsQu
42
42
43
43
public async send ( abortSignal ?: AbortSignal ) {
44
44
const eventsToProcess = this . _events . splice ( 0 ) ;
45
- return await this . submit ( eventsToProcess , anySignal ( abortSignal , this . _abortController . signal ) ) ;
45
+ const signal = anySignal ( abortSignal , this . _abortController . signal ) ;
46
+ try {
47
+ return await this . submit ( eventsToProcess , signal ) ;
48
+ } finally {
49
+ signal . dispose ( ) ;
50
+ }
46
51
}
47
52
48
53
public dispose ( ) {
Original file line number Diff line number Diff line change 13
13
"format" : " prettier --write '**/*.ts'" ,
14
14
"lint" : " eslint . --ext .ts" ,
15
15
"watch" : " npm run build -- --watch" ,
16
+ "prepublishOnly" : " cross-env NODE_ENV=production npm run clean && npm run build" ,
16
17
"test" : " cross-env NODE_OPTIONS=\" $NODE_OPTIONS --experimental-vm-modules\" NODE_NO_WARNINGS=1 NODE_ENV=test jest"
17
18
},
18
19
"repository" : {
You can’t perform that action at this time.
0 commit comments