Giter Site home page Giter Site logo

Comments (7)

braindigitalis avatar braindigitalis commented on May 5, 2024

the error 1000 is an error generated by cloudflare.

the bot is still sending keepalives, but if the server side (discord) sends no traffic for 2 intervals cloudflare disconnects the socket with an error 1000.

the SSL error afterwards is just D++ forced disconnect and resume by invalidating the file descriptor.

in real production use, where the guilds have real traffic, this doesn't happen ( add your invite to a busier server and you'll see).

I don't know how to prevent this as, as ive said heartbeat is being sent (stick some debug in there to find out) and it doesn't disrupt production use.

I'll have a think about what I can do to force the connection to stay open, perhaps by low level websocket pings.

from dpp.

braindigitalis avatar braindigitalis commented on May 5, 2024

It seems sending a low level websocket ping will prevent this (note this is not a discord API keepalive and exists in the level below):

websockets/ws#1436 (comment)

I'll test this later and also look into the hibernation issue, however I don't run my code on anything that hibernates (only on real servers) this can mess with timers and cause issues. I'll let you know what I find out.

from dpp.

fuchsi-fuchs avatar fuchsi-fuchs commented on May 5, 2024

Well the trace level logging seems to include the heartbeat ACKs send by the server R: {"t":null,"s":null,"op":11,"d":null} - and I do see those coming up, but only if there is activity on the server. Are heartbeats only send after a received package was processed instead of after a timer? That would also explain the issue after hibernation as any heartbeat should make it immediately obvious that the connection died.

Thanks for checking it out in any case :-)

from dpp.

fuchsi-fuchs avatar fuchsi-fuchs commented on May 5, 2024

Oh and it is not the hibernation that worries me. Disconnecting my ethernet for a minute has the same effect - and network outages do in fact happen so it would be nice for the bot to handle them correctly ^^

from dpp.

braindigitalis avatar braindigitalis commented on May 5, 2024

no they're sent on a timer, actually 75% of the recommended frequency so if discord says 40 seconds D++ will send them every 30 seconds.

I need to add functionality to ping the underlying websocket, websocket opcode 0x09 to expect a response of type 0x0A. Simply having activity at the application layer above (discord JSON) is not enough to satisfy cloudflare.

this is why you don't see it on other libraries as I've implemented websockets from scratch.

from dpp.

braindigitalis avatar braindigitalis commented on May 5, 2024

This is now fixed in 1.0.1 dev branch, commit 6cf1d27.
We needed to send a low level websocket opcode 0x9 every 30 seconds to stop cloudflare disconnecting the websocket with close code 1000. For each 0x9 we send, we receive a low level 0xa.
The attempt to send the 0x9 will also trigger the socket error routine if the connection has died.
Please let me know if there continue to be issues.

from dpp.

fuchsi-fuchs avatar fuchsi-fuchs commented on May 5, 2024

The commit seems to fix the issue for me. Heartbeats are send out (EDIT: acks are received) every ~30sec. After network disconnect it reconnects quickly and creates a new session as resuming it wasn't possible.

Thanks :-)

from dpp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.