socketio / socket.io

Realtime application framework (Node.JS server)
https://socket.io
MIT License
61.22k stars 10.11k forks source link

Unstable connection using socket.io in an Electron-Vue app #3753

Closed groboter closed 1 year ago

groboter commented 3 years ago

Describe the bug I'm using socket.io in an Electron - Vue app to connect to a server running on Raspberry Pi.

But the connection is very unstable it connects and disconnects randomly. Sometimes the connection seems to be stable for a longer time in minutes and sometimes it toggles within seconds.

I have not a lot of experience in debugging and don't know how to find out what happens. I don't think that it is a network problem because I'm running only a few devices on my network (1 to 4 smartphones and computers) and I do not have other network problems.

The following errors are from a time window < 1 minute.

Client Errors

┏ Electron -------------------
  SocketIO: Connected HQW367HrKw6LlID7AAAA
  SocketIO: Disconnected reason : transport error
  SocketIO: Connected wgU-FJtmmuarhDsRAAAB
  SocketIO: Disconnected reason : transport error
  SocketIO: Connected QTC_BscYa8PzKXbqAAAC
  SocketIO: Disconnected reason : transport error
  SocketIO: Connected DQF4Q8ErANH3AWxDAAAD
  SocketIO: Disconnected reason : transport error
  SocketIO: Connected QXmbxbViXnvLQ7aeAAAE
  SocketIO: Disconnected reason : transport error
  SocketIO: Connected I9IOwcHWz49rvXZCAAAF
  SocketIO: Disconnected reason : transport error

Server errors

User connected HQW367HrKw6LlID7AAAA
User connected wgU-FJtmmuarhDsRAAAB
User disconnected wgU-FJtmmuarhDsRAAAB
--> still CONNECTED wgU-FJtmmuarhDsRAAAB
User connected QTC_BscYa8PzKXbqAAAC
User connected DQF4Q8ErANH3AWxDAAAD
User connected QXmbxbViXnvLQ7aeAAAE
User connected I9IOwcHWz49rvXZCAAAF
User connected Dj0TA_UwJW2WEwJnAAAG
User disconnected HQW367HrKw6LlID7AAAA
--> still CONNECTED HQW367HrKw6LlID7AAAA
User disconnected QTC_BscYa8PzKXbqAAAC
--> still CONNECTED QTC_BscYa8PzKXbqAAAC
User disconnected DQF4Q8ErANH3AWxDAAAD
--> still CONNECTED DQF4Q8ErANH3AWxDAAAD
User disconnected QXmbxbViXnvLQ7aeAAAE
--> still CONNECTED QXmbxbViXnvLQ7aeAAAE
User disconnected I9IOwcHWz49rvXZCAAAF
--> still CONNECTED I9IOwcHWz49rvXZCAAAF

To Reproduce

Server

import { Server } from "socket.io";

const io = new Server(3000, {});

io.on("connection", (socket) => {
  console.log(`connect ${socket.id}`);

  socket.on("disconnect", () => {
    console.log(`disconnect ${socket.id}`);
  });
});

Socket.IO client version: x.y.z

Client

import { io } from "socket.io-client";

const socket = io('http://name.local:3000', { 'forceNew':true });

socket.on("connect", () => {
  console.log(`connect ${socket.id}`);
});

socket.on("disconnect", () => {
  console.log("disconnect");
});

Client Dependecies

"dependencies": {
    "bootstrap": "^4.5.2",
    "bootstrap-vue": "^2.17.3",
    "sharp": "^0.26.2",
    "simple-statistics": "^7.3.2",
    "socket.io": "^2.3.0",
    "vue": "^2.6.12",
    "vue-electron": "^1.0.6",
    "vue-router": "^3.0.1",
    "vuex": "^3.0.1",
    "vuex-electron": "^1.0.0",
    "xstate": "^4.13.0"
  },
  "devDependencies": {
    "ajv": "^6.5.0",
    "babel-core": "^6.26.3",
    "babel-loader": "^7.1.4",
    "babel-minify-webpack-plugin": "^0.3.1",
    "babel-plugin-transform-runtime": "^6.23.0",
    "babel-preset-env": "^1.7.0",
    "babel-preset-stage-0": "^6.24.1",
    "babel-register": "^6.26.0",
    "cfonts": "^2.1.2",
    "chalk": "^2.4.1",
    "copy-webpack-plugin": "^4.5.1",
    "cross-env": "^5.1.6",
    "css-loader": "^0.28.11",
    "del": "^3.0.0",
    "devtron": "^1.4.0",
    "electron": "^10.1.2",
    "electron-builder": "^20.19.2",
    "electron-debug": "^1.5.0",
    "electron-devtools-installer": "^2.2.4",
    "file-loader": "^1.1.11",
    "html-webpack-plugin": "^3.2.0",
    "mini-css-extract-plugin": "0.4.0",
    "multispinner": "^0.2.1",
    "node-loader": "^0.6.0",
    "style-loader": "^0.21.0",
    "url-loader": "^1.0.1",
    "vue-html-loader": "^1.2.4",
    "vue-loader": "^15.2.4",
    "vue-style-loader": "^4.1.0",
    "vue-template-compiler": "^2.5.16",
    "webpack": "^4.15.1",
    "webpack-cli": "^3.0.8",
    "webpack-dev-server": "^3.1.4",
    "webpack-hot-middleware": "^2.22.2",
    "webpack-merge": "^4.1.3"
  }

Server Dependecies

  "dependencies": {
    "chalk": "^4.1.0",
    "ejs": "^3.1.5",
    "express": "^4.17.1",
    "path": "^0.12.7",
    "polycrc": "^1.0.1",
    "raspi": "^6.0.1",
    "raspi-board": "^7.3.3",
    "raspi-gpio": "^6.2.2",
    "raspi-peripheral": "^3.0.4",
    "raspi-pwm": "^6.0.0",
    "serialport": "^9.0.2",
    "serve-favicon": "^2.5.0",
    "simple-statistics": "^7.3.0",
    "socket.io": "^2.3.0",
    "systeminformation": "^4.27.10"
  }

Expected behavior Connection should be persistent.

Platform: The client is running on WIN10 PC and the server on Raspberry Pi 4 using Raspian 10 (buster).

joezappie commented 3 years ago

I too am finding my clients often randomly drop connection and immediate reconnect even when everything is pretty much idle. This happens in both my Electron Win10 app and on a Raspberry Pi's running node V13 with no frameworks. Seems like its platform agnostic for this issue to me.

RinChanNOWWW commented 3 years ago

My electron-react app(macOS) also disconnects randomly and establishes a new connection with a new sid.

h5aaimtron commented 3 years ago

I'm seeing the same issue (Angular + all websocket libs) after updating electron to the latest version with one of my users. They're constantly disconnecting/reconnect. Other users aren't as bad, but do seem to also experience the issue. The server reports that the client disconnected gracefully regardless of the web socket lib I'm running (signalr core and socket.io). I have noticed that if chrome is idle, the socket connection gets dropped. Not sure if that is related.

isaquebc commented 3 years ago

Other users aren't as bad, but do seem

Same here, backend api with nestjs

octopoulos commented 3 years ago

It's not a bug. The library is unfortunately very slow and unstable, I just ran some very basic benchmark with pub/sub (room) and as soon as I try to send too many requests per second, it starts freezing and then drops the connection after a minute or so.

h5aaimtron commented 3 years ago

I think the common denominator here is Electron.io honestly. I'm testing out the disabling of the backgroundThrottling as I suspect that causes the issue.

joaogn commented 2 years ago

I think the common denominator here is Electron.io honestly. I'm testing out the disabling of the backgroundThrottling as I suspect that causes the issue.

Do you have some results with your tests?

darrachequesne commented 1 year ago

For future readers:

I think this should now be fixed in latest versions:

Please reopen if needed.