Skip to content

feat(sio): add ackTimeout option and enable emitWithAck on io/namespace#5479

Open
976520 wants to merge 2 commits intosocketio:mainfrom
976520:feat/server-ack-timeout
Open

feat(sio): add ackTimeout option and enable emitWithAck on io/namespace#5479
976520 wants to merge 2 commits intosocketio:mainfrom
976520:feat/server-ack-timeout

Conversation

@976520
Copy link

@976520 976520 commented Mar 19, 2026

The kind of change this PR does introduce

  • a bug fix
  • a new feature
  • an update to the documentation
  • a code change that improves performance
  • other

Current behavior

socket.to(room).emitWithAck() requires an explicit .timeout() call, otherwise the operation immediately fails. There is also no way to set a default acknowledgement timeout at the server level, unlike the client side ackTimeout option.

io.emitWithAck() and namespace.emitWithAck() are not available, as they were intentionally disabled due to the lack of a default timeout mechanism.

New behavior

A new ackTimeout option can be set on the server, mirroring the client side ackTimeout option. When set, it is used as the
default timeout for emitWithAck() calls that do not have an explicit .timeout() set.

  const io = new Server(httpServer, { ackTimeout: 5000 });                                                                        
                                                                                                                                  
  // now works without explicit .timeout()                                                                                        
  const responses = await socket.to(room).emitWithAck("some-event");                                                              
                                                                                                                                  
  // io and namespace level emitWithAck are also now enabled                                                                      
  const responses = await io.emitWithAck("some-event");                                                                           
  const responses = await io.of("/chat").emitWithAck("some-event");                                                               

An explicit .timeout() call still takes precedence over the default

Other information (e.g. related issues)

#5333

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant