File tree Expand file tree Collapse file tree 3 files changed +30
-1
lines changed Expand file tree Collapse file tree 3 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -38,7 +38,7 @@ export class Polling extends Transport {
38
38
* @private
39
39
*/
40
40
private onPollRequest (
41
- _req : Request ,
41
+ req : Request ,
42
42
responseHeaders : Headers ,
43
43
) : Promise < Response > {
44
44
if ( this . pollingPromise ) {
@@ -51,6 +51,10 @@ export class Polling extends Transport {
51
51
52
52
debug ( "new polling request" ) ;
53
53
54
+ req . signal . addEventListener ( "abort" , ( ) => {
55
+ this . onError ( "polling request aborted" ) ;
56
+ } ) ;
57
+
54
58
return new Promise < Response > ( ( resolve , reject ) => {
55
59
this . pollingPromise = { resolve, reject, responseHeaders } ;
56
60
@@ -72,6 +76,10 @@ export class Polling extends Transport {
72
76
) : Promise < Response > {
73
77
debug ( "new data request" ) ;
74
78
79
+ req . signal . addEventListener ( "abort" , ( ) => {
80
+ this . onError ( "data request aborted" ) ;
81
+ } ) ;
82
+
75
83
const data = await req . text ( ) ;
76
84
77
85
if ( data . length > this . opts . maxHttpBufferSize ) {
Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ async function initLongPollingSession() {
14
14
return JSON . parse ( content . substring ( 1 ) ) . sid ;
15
15
}
16
16
17
+ // imported from https://github.com/socketio/socket.io/blob/main/docs/engine.io-protocol/v4-test-suite
17
18
describe ( "Engine.IO protocol" , ( ) => {
18
19
beforeAll ( ( ) => {
19
20
const engine = new Server ( {
@@ -313,6 +314,25 @@ describe("Engine.IO protocol", () => {
313
314
314
315
expect ( pollResponse . status ) . toEqual ( 400 ) ;
315
316
} ) ;
317
+
318
+ it ( "closes the session upon cancelled polling request" , async ( ) => {
319
+ const sid = await initLongPollingSession ( ) ;
320
+ const controller = new AbortController ( ) ;
321
+
322
+ fetch ( `${ URL } /engine.io/?EIO=4&transport=polling&sid=${ sid } ` , {
323
+ signal : controller . signal ,
324
+ } ) . catch ( ( ) => { } ) ;
325
+
326
+ await sleep ( 5 ) ;
327
+
328
+ controller . abort ( ) ;
329
+
330
+ const pollResponse = await fetch (
331
+ `${ URL } /engine.io/?EIO=4&transport=polling&sid=${ sid } ` ,
332
+ ) ;
333
+
334
+ expect ( pollResponse . status ) . toEqual ( 400 ) ;
335
+ } ) ;
316
336
} ) ;
317
337
318
338
describe ( "WebSocket" , ( ) => {
Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ async function initSocketIOConnection() {
25
25
return socket ;
26
26
}
27
27
28
+ // imported from https://github.com/socketio/socket.io/tree/main/docs/socket.io-protocol/v5-test-suite
28
29
describe ( "Socket.IO protocol" , ( ) => {
29
30
beforeAll ( ( ) => {
30
31
const io = new Server ( ) ;
You can’t perform that action at this time.
0 commit comments