liamcottle / rustplus.js

Unofficial NodeJS library for controlling Smart Switches in the PC game Rust
224 stars 46 forks source link

Listeners stop responding after 2 hours #16

Closed Gruntwill closed 3 years ago

Gruntwill commented 3 years ago

Me and a friend have been making separate bots using the library, but we've noticed it seems to disconnect after a couple of hours usually. There's no error message or crash, but it just stops picking up anything on the listeners until I restart the program or figure out a way to reconnect. I tried to implement a simple fix by listening for a disconnect but that didn't trigger either. Have you had any experience with this? image image (More messages were sent after this but aren't picked up)

liamcottle commented 3 years ago

I haven't had any long listeners running, but my guess is you aren't sending any requests to the websocket after you've setup your listener, and so after a while the TCP connection just becomes stale.

Usually there's some sort of ping/pong implementation that's used with websockets to keep the underlying connection alive, but in the case of the Rust+ app they send requests to fetch info from the server every few moments or so, which would keep the TCP connection alive without needing another ping/pong packet.

You could try adding a timer that sends a getInfo request or something every now and again and seeing if that solves the issue.

Also, I'm assuming the websocket isn't emitting the onclose event, which I use to emit the disconnected event, because the server never sent a close frame.

Let me know if this solves your issue :)

Gruntwill commented 3 years ago

Thanks for the help! Seinding a getInfo request every 10 seconds now and it's been going about 3 hours without issue now, I'll try it again tomorrow for longer though.