1
0
Fork 0
mirror of https://github.com/diamondburned/arikawa.git synced 2025-03-23 02:19:22 +00:00

session: Fix Connect->Open not handling ctx

This commit is contained in:
diamondburned 2022-11-20 20:30:57 -08:00
parent 4db60bca9d
commit 789afaa88f
No known key found for this signature in database
GPG key ID: D78C4471CE776659

View file

@ -231,19 +231,25 @@ func (s *Session) Connect(ctx context.Context) error {
for { for {
if err := s.Open(ctx); err != nil { if err := s.Open(ctx); err != nil {
if opts.ErrorIsFatalClose(err) { if opts.ErrorIsFatalClose(err) || ctx.Err() != nil {
// Fatal error or context is done, return.
return err return err
} }
// Non-fatal error, retry.
continue continue
} }
if err := s.Wait(ctx); err != nil { if err := s.Wait(ctx); err != nil {
if opts.ErrorIsFatalClose(err) { if opts.ErrorIsFatalClose(err) {
// Gateway returned a fatal error, so we can't recover.
return err return err
} }
if ctx.Err() == nil { if ctx.Err() != nil {
return err // Context was done, so we can't recover. Exit with no error,
// since we're just waiting.
return nil
} }
// Non-fatal error, retry.
} }
} }
} }