mirror of
https://github.com/diamondburned/arikawa.git
synced 2024-11-27 09:12:53 +00:00
Gateway: Fixed infinite InvalidSession loop
This commit is contained in:
parent
e95227d3f5
commit
813be25713
|
@ -195,7 +195,7 @@ func (g *Gateway) Reconnect() {
|
|||
// If the connection is rate limited (documented behavior):
|
||||
// https://discordapp.com/developers/docs/topics/gateway#rate-limiting
|
||||
|
||||
if err := g.Open(); err != nil && err != ErrInvalidSession {
|
||||
if err := g.Open(); err != nil {
|
||||
g.ErrorLog(errors.Wrap(err, "Failed to open gateway"))
|
||||
continue
|
||||
}
|
||||
|
@ -282,6 +282,7 @@ func (g *Gateway) start() error {
|
|||
// Expect either READY or RESUMED before continuing.
|
||||
WSDebug("Waiting for either READY or RESUMED.")
|
||||
|
||||
// WaitForEvent should
|
||||
err := WaitForEvent(g, ch, func(op *OP) bool {
|
||||
switch op.EventName {
|
||||
case "READY":
|
||||
|
|
|
@ -38,8 +38,6 @@ type OP struct {
|
|||
EventName string `json:"t,omitempty"`
|
||||
}
|
||||
|
||||
var ErrInvalidSession = errors.New("Invalid session")
|
||||
|
||||
func DecodeEvent(driver json.Driver, ev wsutil.Event, v interface{}) (OPCode, error) {
|
||||
op, err := DecodeOP(driver, ev)
|
||||
if err != nil {
|
||||
|
@ -91,16 +89,16 @@ func WaitForEvent(g *Gateway, ch <-chan wsutil.Event, fn func(*OP) bool) error {
|
|||
return err
|
||||
}
|
||||
|
||||
// Are these events what we're looking for?
|
||||
found := fn(o)
|
||||
|
||||
// Handle the *OP anyway.
|
||||
// Handle the *OP first, in case it's an Invalid Session. This should
|
||||
// also prevent a race condition with things that need Ready after
|
||||
// Open().
|
||||
if err := HandleOP(g, o); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// If we found the event, return.
|
||||
if found {
|
||||
// Are these events what we're looking for? If we've found the event,
|
||||
// return.
|
||||
if fn(o) {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
@ -122,10 +120,6 @@ func DecodeOP(driver json.Driver, ev wsutil.Event) (*OP, error) {
|
|||
return nil, errors.Wrap(err, "OP error: "+string(ev.Data))
|
||||
}
|
||||
|
||||
if op.Code == InvalidSessionOP {
|
||||
return op, ErrInvalidSession
|
||||
}
|
||||
|
||||
return op, nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue