session: Fix Connect->Open not handling ctx

This commit is contained in:
diamondburned 2022-11-20 20:30:57 -08:00
parent 4db60bca9d
commit 1e59f37294
No known key found for this signature in database
GPG Key ID: D78C4471CE776659
1 changed files with 9 additions and 3 deletions

View File

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