File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -234,6 +234,7 @@ export class Socket<
234
234
235
235
const timer = setTimeout ( ( ) => {
236
236
debug ( "event with ack id %d has timed out after %d ms" , id , timeout ) ;
237
+ this . acks . delete ( id ) ;
237
238
ack . call ( this , new Error ( "operation has timed out" ) ) ;
238
239
} , timeout ) ;
239
240
Original file line number Diff line number Diff line change @@ -15,6 +15,29 @@ describe("timeout", () => {
15
15
} ) ;
16
16
} ) ;
17
17
18
+ it ( "should timeout if the client does not acknowledge the event in time" , ( done ) => {
19
+ const io = new Server ( 0 ) ;
20
+ const client = createClient ( io , "/" ) ;
21
+
22
+ client . on ( "echo" , ( arg , cb ) => {
23
+ cb ( arg ) ;
24
+ } ) ;
25
+
26
+ let count = 0 ;
27
+
28
+ io . on ( "connection" , ( socket ) => {
29
+ socket . timeout ( 0 ) . emit ( "echo" , 42 , ( err ) => {
30
+ expect ( err ) . to . be . an ( Error ) ;
31
+ count ++ ;
32
+ } ) ;
33
+ } ) ;
34
+
35
+ setTimeout ( ( ) => {
36
+ expect ( count ) . to . eql ( 1 ) ;
37
+ success ( done , io , client ) ;
38
+ } , 200 ) ;
39
+ } ) ;
40
+
18
41
it ( "should not timeout if the client does acknowledge the event" , ( done ) => {
19
42
const io = new Server ( 0 ) ;
20
43
const client = createClient ( io , "/" ) ;
You can’t perform that action at this time.
0 commit comments