Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

emitWithAck does not throw on disconnect #4964

Closed
jd1378 opened this issue Feb 29, 2024 · 3 comments
Closed

emitWithAck does not throw on disconnect #4964

jd1378 opened this issue Feb 29, 2024 · 3 comments
Labels
bug Something isn't working
Milestone

Comments

@jd1378
Copy link

jd1378 commented Feb 29, 2024

Describe the bug
Take the following steps:

  • put browser into offline mode
  • use emitWithAck to send a message immediately
  • expect emitWithAck to throw on disconnect, but it does not
  • put browser into online mode and reconnect.
  • emitWithAck still not resolving.

To Reproduce

Socket.IO client and server version: 4.7.4

I used the socket.io chat example to make a reproduction repo:
https://github.com/jd1378/socketio-emit-ack-bug

Expected behavior

I expect the emitWithAck to throw once the socket is disconnected. OR, I expect emitWithAck to retry the request, as it's not volatile.

Platform:

  • Windows 10, Edge browser

Additional context

What's even better than the expected behavior? a new option to control the behavior.

what I really want is to be able to detect the failure of my requests and throw, much like how a fetch request would throw if connection fails. and I don't want to retry the request automatically when it's thrown.

@jd1378 jd1378 added the to triage Waiting to be triaged by a member of the team label Feb 29, 2024
@darrachequesne
Copy link
Member

I could indeed reproduce, thanks for the test case. I'm digging into this.

Related: socketio/socket.io-client#1546

@darrachequesne darrachequesne added bug Something isn't working and removed to triage Waiting to be triaged by a member of the team labels Mar 13, 2024
darrachequesne added a commit to socketio/socket.io-client that referenced this issue Mar 14, 2024
Previously, getting disconnected while waiting for an acknowledgement
would create a memory leak, as the acknowledgement was never received
and the handler would stay in memory forever.

This commit fixes the issue:

- handlers that do accept an error as first argument, such as:

* `socket.emit("test", (err, value) => { ... })` with `ackTimeout` option
* `socket.timeout(5000).emit("test", (err, value) => { ... })`
* `const value = await socket.emitWithAck("test")`

will now properly resolve with an error and get discarded.

- handlers that don't like `socket.emit("test", (value) => { ... });`
will simply be discarded upon disconnection

Note: the structure of the 'acks' attribute has been left untouched, in
order to prevent any breaking change.

Related:

- #1546
- socketio/socket.io#4964
@darrachequesne
Copy link
Member

This should be fixed by socketio/socket.io-client@34cbfbb, included in version 4.7.5.

@jd1378 could you please check?

@jd1378
Copy link
Author

jd1378 commented Mar 14, 2024

Hi
I can confirm this is now working as expected by testing again using the reproduction repo
thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants