1
0
Fork 0
mirror of https://github.com/diamondburned/arikawa.git synced 2024-09-27 20:58:50 +00:00

Gateway: Fixed wrong usage of Context in Gateway reconnection

This commit is contained in:
diamondburned 2020-07-15 16:32:53 -07:00
parent 880691c51b
commit a1038cb8bb

View file

@ -202,14 +202,13 @@ func (g *Gateway) Close() error {
// Reconnect tries to reconnect forever. It will resume the connection if // Reconnect tries to reconnect forever. It will resume the connection if
// possible. If an Invalid Session is received, it will start a fresh one. // possible. If an Invalid Session is received, it will start a fresh one.
func (g *Gateway) Reconnect() error { func (g *Gateway) Reconnect() {
ctx, cancel := context.WithTimeout(context.Background(), g.WSTimeout) g.ReconnectCtx(context.Background())
defer cancel()
return g.ReconnectCtx(ctx)
} }
func (g *Gateway) ReconnectCtx(ctx context.Context) error { // ReconnectCtx attempts to reconnect until context expires. If context cannot
// expire, then the gateway will try to reconnect forever.
func (g *Gateway) ReconnectCtx(ctx context.Context) {
wsutil.WSDebug("Reconnecting...") wsutil.WSDebug("Reconnecting...")
// Guarantee the gateway is already closed. Ignore its error, as we're // Guarantee the gateway is already closed. Ignore its error, as we're
@ -225,11 +224,10 @@ func (g *Gateway) ReconnectCtx(ctx context.Context) error {
if err := g.OpenContext(ctx); err != nil { if err := g.OpenContext(ctx); err != nil {
g.ErrorLog(errors.Wrap(err, "failed to open gateway")) g.ErrorLog(errors.Wrap(err, "failed to open gateway"))
continue
} }
wsutil.WSDebug("Started after attempt:", i) wsutil.WSDebug("Started after attempt:", i)
return nil return
} }
} }