arikawa icon indicating copy to clipboard operation
arikawa copied to clipboard

v3: gateway: Reconnect after heartbeat misses

Open diamondburned opened this issue 3 years ago • 1 comments

Currently, the gateway does not try to reconnect if it detects that the gateway's last heartbeat ACK was behind time. This is an issue when the computer is suspended for a long period of time, but it might also be an issue in machines with spotty network conditions.

Ideally, utils/ws should handle the check, so we can have something like:

 type Handler interface {
        // OnOp is called by the gateway event loop on every new Op. If the returned
        // boolean is false, then the loop fatally exits.
-       OnOp(context.Context, Op) (canContinue bool)
+       OnOp(context.Context, Op) (heartbeat time.Time, canContinue bool)
        // SendHeartbeat is called by the gateway event loop everytime a heartbeat
        // needs to be sent over.
        SendHeartbeat(context.Context)

or

@@ -122,6 +122,8 @@ type Handler interface {
        // OnOp is called by the gateway event loop on every new Op. If the returned
        // boolean is false, then the loop fatally exits.
        OnOp(context.Context, Op) (canContinue bool)
+       // LastBeat returns the last heartbeat time.
+       LastBeat() time.Time
        // SendHeartbeat is called by the gateway event loop everytime a heartbeat
        // needs to be sent over.
        SendHeartbeat(context.Context)

The first method wouldn't require re-locking the state mutex after each loop iteration, so it seems like the better solution to me. Overloading the return type might be kind of weird, though.

diamondburned avatar Apr 12 '22 16:04 diamondburned

https://github.com/diamondburned/arikawa/commit/660d9893e1cb813f7672ce6ab34a5cc2363ea16d introduced a regression.

diamondburned avatar Apr 12 '22 18:04 diamondburned