-
Notifications
You must be signed in to change notification settings - Fork 10.1k
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
Add timeout method to remote socket #4558
Conversation
I ran into the same issue today. The bug means you can't actually receive client ack's in all scenarios when using an adapter in clustered servers. I am working around it for now by writing to the |
@walde1024 thanks for opening this pull request 👍 The only problem is that local and remote Sockets will not behave similarly, because local Socket will expect one single response: socket.timeout(1000).emit("hello", (err, res) => {
console.log(Array.isArray(res)); // false
}); While a remote Socket will return an array with a single response (since it's a broadcast under the hood): remoteSocket.timeout(1000).emit("hello", (err, res) => {
console.log(Array.isArray(res)); // true
}); |
Thanks for your reply. My understanding of socket.io and how it works under the hood is very basic but isn't the problem you are mentioning already there? My PR just exposes the timeout method. The handling of the response stays as it is. Right now the caller of the emit method needs to know that he is calling emit on a socket or on a remote socket because:
My PR would just solve the first point including the bug that the timeout hits immediately. |
@walde1024 you are right, I was just wondering whether we could elegantly fix both problems. |
The RemoteSocket interface, which is returned when the client is connected on another Socket.IO server of the cluster, was lacking the `timeout()` method. Syntax: ```js const sockets = await io.fetchSockets(); for (const socket of sockets) { if (someCondition) { socket.timeout(1000).emit("some-event", (err) => { if (err) { // the client did not acknowledge the event in the given delay } }); } } ``` Related: #4595
Merged as 0c0eb00. Thanks a lot 👍 |
thanks for fixing! i came here to report this issue but see its finished |
The RemoteSocket interface, which is returned when the client is connected on another Socket.IO server of the cluster, was lacking the `timeout()` method. Syntax: ```js const sockets = await io.fetchSockets(); for (const socket of sockets) { if (someCondition) { socket.timeout(1000).emit("some-event", (err) => { if (err) { // the client did not acknowledge the event in the given delay } }); } } ``` Related: socketio#4595
The RemoteSocket interface, which is returned when the client is connected on another Socket.IO server of the cluster, was lacking the `timeout()` method. Syntax: ```js const sockets = await io.fetchSockets(); for (const socket of sockets) { if (someCondition) { socket.timeout(1000).emit("some-event", (err) => { if (err) { // the client did not acknowledge the event in the given delay } }); } } ``` Related: socketio#4595
The kind of change this PR does introduce
Current behavior
The RemoteSocket does currently not expose a timeout method. With that I encountered problems when emitting events by using a remote socket that I fetched from another instance by using the redis adapter.
When I emit a message like this:
then the client receives the emitted message but the callback of the sender is invoked immediately with a timeout error. Reason for that is that the flags.timeout of the BroadcastOperator is not set when emitting the message.
New behavior
Exposes a timeout method that can be called on the RemoteSocket to set a timeout.
Other information (e.g. related issues)
I encountered this problem by using the following dependencies:
The following piece of code can be used to reproduce the issue: