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):
|
// If the connection is rate limited (documented behavior):
|
||||||
// https://discordapp.com/developers/docs/topics/gateway#rate-limiting
|
// 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"))
|
g.ErrorLog(errors.Wrap(err, "Failed to open gateway"))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -282,6 +282,7 @@ func (g *Gateway) start() error {
|
||||||
// Expect either READY or RESUMED before continuing.
|
// Expect either READY or RESUMED before continuing.
|
||||||
WSDebug("Waiting for either READY or RESUMED.")
|
WSDebug("Waiting for either READY or RESUMED.")
|
||||||
|
|
||||||
|
// WaitForEvent should
|
||||||
err := WaitForEvent(g, ch, func(op *OP) bool {
|
err := WaitForEvent(g, ch, func(op *OP) bool {
|
||||||
switch op.EventName {
|
switch op.EventName {
|
||||||
case "READY":
|
case "READY":
|
||||||
|
|
|
@ -38,8 +38,6 @@ type OP struct {
|
||||||
EventName string `json:"t,omitempty"`
|
EventName string `json:"t,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var ErrInvalidSession = errors.New("Invalid session")
|
|
||||||
|
|
||||||
func DecodeEvent(driver json.Driver, ev wsutil.Event, v interface{}) (OPCode, error) {
|
func DecodeEvent(driver json.Driver, ev wsutil.Event, v interface{}) (OPCode, error) {
|
||||||
op, err := DecodeOP(driver, ev)
|
op, err := DecodeOP(driver, ev)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -91,16 +89,16 @@ func WaitForEvent(g *Gateway, ch <-chan wsutil.Event, fn func(*OP) bool) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Are these events what we're looking for?
|
// Handle the *OP first, in case it's an Invalid Session. This should
|
||||||
found := fn(o)
|
// also prevent a race condition with things that need Ready after
|
||||||
|
// Open().
|
||||||
// Handle the *OP anyway.
|
|
||||||
if err := HandleOP(g, o); err != nil {
|
if err := HandleOP(g, o); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we found the event, return.
|
// Are these events what we're looking for? If we've found the event,
|
||||||
if found {
|
// return.
|
||||||
|
if fn(o) {
|
||||||
return nil
|
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))
|
return nil, errors.Wrap(err, "OP error: "+string(ev.Data))
|
||||||
}
|
}
|
||||||
|
|
||||||
if op.Code == InvalidSessionOP {
|
|
||||||
return op, ErrInvalidSession
|
|
||||||
}
|
|
||||||
|
|
||||||
return op, nil
|
return op, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue