Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v3: gateway: Reconnect after heartbeat misses #324

Open
diamondburned opened this issue Apr 12, 2022 · 1 comment
Open

v3: gateway: Reconnect after heartbeat misses #324

diamondburned opened this issue Apr 12, 2022 · 1 comment

Comments

@diamondburned
Copy link
Owner

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
Copy link
Owner Author

660d989 introduced a regression.

diamondburned added a commit that referenced this issue Apr 14, 2022
This commit adds ws.Handler.LastAcknowledgedBeat to allow ws.Gateway to
monitor whether or not the server is still reachable.

It fixes #324.
diamondburned added a commit that referenced this issue Apr 14, 2022
This commit adds ws.Handler.LastAcknowledgedBeat to allow ws.Gateway to
monitor whether or not the server is still reachable.

It fixes #324.
diamondburned added a commit that referenced this issue Apr 18, 2022
This commit adds ws.Handler.LastAcknowledgedBeat to allow ws.Gateway to
monitor whether or not the server is still reachable.

It fixes #324.
diamondburned added a commit that referenced this issue May 11, 2022
This commit adds ws.Handler.LastAcknowledgedBeat to allow ws.Gateway to
monitor whether or not the server is still reachable.

It fixes #324.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant