Skip to content

socket.emit to invoke ack callback with an Error if the transport closes #1546

Closed
@jbaudanza

Description

Is your feature request related to a problem? Please describe.
Our app operates in some areas with poor internet connectivity, and network interruptions are quite common. When our client's call socket.emit, often the underlaying websocket will close before the message reaches the server. Since the socket was connected at the time of the emit, the messages aren't added to the this.sendBuffer queue. So, effectively, they are lost. And the application code waits indefinitely for the ack callabck.

Describe the solution you'd like
I would like a feature similar to the timeout() feature, but for transport close events.

When a "close" event is received on a transport, any remaining entries in this.acks should be invoked with an Error, and removed. Since the transport is closed, there is no hope of an actual ack coming from the server. This should also prevent some memory leak issues, because this.acks is holding references to functions for acks that will never come.

When the application receives the Error callback, it can decide if it wants to retry the emit, or to inform the user of the failure.

Describe alternatives you've considered
This functionality could probably be built into the application layer above socketio. But, it would fit more cleanly into the this.acks datastructure. The application also doesn't have the ability to clean out the this.acks data structure, which could lead to memory leaks.

Additional context
I'm happy to put together a PR for this.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions