socket.io
socket.io copied to clipboard
Function after socket.emit is not executed
Describe the bug After socket emits error there is no code executed after that.
To Reproduce My code is for work with Twitter stream Server
.stream
.on("data", (data) => {
console.log("pojawily sie jakie dane");
try {
const json = JSON.parse(data);
if (json.connection_issue) {
socket.emit("error",json);
reconnect(stream,socket,token); //not executed
} else {
if (json.data) {
socket.emit("tweet",json);
fs.appendFileSync("log.txt",json); // not executed
}
else {
socket.emit("AuthError",json);
console.log("trying to reconnect"); //not executed
reconnect(stream,socket,token,timeout); //not executed
}
}
Expected behavior Normal code execution
Platform:
- Device: VPS
- OS: Ubuntu 18.04
Additional context Add any other context about the problem here.
Describe the bug After socket emits error there is no code executed after that.
To Reproduce My code is for work with Twitter stream Server
.stream .on("data", (data) => { console.log("pojawily sie jakie dane"); try { const json = JSON.parse(data); if (json.connection_issue) { socket.emit("error",json); reconnect(stream,socket,token); //not executed } else { if (json.data) { socket.emit("tweet",json); fs.appendFileSync("log.txt",json); // not executed } else { socket.emit("AuthError",json); console.log("trying to reconnect"); //not executed reconnect(stream,socket,token,timeout); //not executed } }Expected behavior Normal code execution
Platform:
- Device: VPS
- OS: Ubuntu 18.04
Additional context Add any other context about the problem here.
Describe the bug After socket emits error there is no code executed after that.
This is not a bug. In socket.io, error is a reserved event name and it will crash the server if you emit to any socket using this name (#2285). Simply use another name instead of error, like jsonError.
I think your solution won't apply here , because whenever twitter stream is disconnected for operational reasons, "AuthError" event is emitted (code in second else block). And server is not crashing, but reconnect is not executed. if reserved event name crashes the serves this is certainly bug, not a feature. If I recal even Twitter used that word in their demo code.
In socket.io, error is a reserved event name
This was true in Socket.IO v2, but this is not true anymore. The list of reserved event names, as of Socket.IO v3/v4:
- connect
- connect_error
- disconnect
- disconnecting
- newListener
- removeListener
Reference: https://socket.io/docs/v4/emit-cheatsheet/#Reserved-events
@Behinder could you please provide a complete example reproducing the issue? You can fork https://github.com/socketio/socket.io-fiddle
Sure. You need Bearer token from twitter API to make it work. I deleted unnecessary stuff from client.js what is left should illustrate the problem. run server and in another terminal session client and wait for "disconnect due to operational error" appear and then you see twitter stream is not going to re-connect and no log is saved. I marked code as //Not executed inside.
I hope this works, as I never reported bugs by forking before. https://github.com/Behinder/socket.io-fiddle
Closed due to inactivity, please reopen if needed.
if nobody wanted to try and check no wonder it's not active. Suddenly it started to work in version 3 so I am not sure what happen.
On Tue, Jan 18, 2022 at 8:43 AM Damien Arrachequesne < @.***> wrote:
Closed due to inactivity, please reopen if needed.
— Reply to this email directly, view it on GitHub https://github.com/socketio/socket.io/issues/3873#issuecomment-1015146054, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAEQPFVWV6VQ4OFFDCYYHVTUWUK2ZANCNFSM422HCC6Q . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
You are receiving this because you were mentioned.Message ID: @.***>
@Behinder sorry for dismissing the issue! I'll check the example you provided.
No problem, as I said it looks it fixed somehow itself even in version 3 but I believe it may stop work out of a sudden :)
On Thu, Jan 20, 2022 at 10:46 AM Damien Arrachequesne < @.***> wrote:
@Behinder https://github.com/Behinder sorry for dismissing the issue! I'll check the example you provided.
— Reply to this email directly, view it on GitHub https://github.com/socketio/socket.io/issues/3873#issuecomment-1017292792, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAEQPFSH74AYCBDPH7AJKILUW7KYNANCNFSM422HCC6Q . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
You are receiving this because you were mentioned.Message ID: @.***>