Skip to content

Commit 34c5c1a

Browse files
committed
Avoid wait callback when context expires
1 parent d4170ca commit 34c5c1a

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

agent/reconnectingpty/buffered.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ func (rpty *bufferedReconnectingPTY) Attach(ctx context.Context, connID string,
191191
}
192192

193193
if state != StateReady {
194-
return xerrors.Errorf("reconnecting pty ready wait: %w", err)
194+
return err
195195
}
196196

197197
go heartbeat(ctx, rpty.timer, rpty.timeout)
@@ -210,7 +210,7 @@ func (rpty *bufferedReconnectingPTY) Attach(ctx context.Context, connID string,
210210
return nil
211211
})
212212
if err != nil {
213-
return err
213+
return xerrors.Errorf("reconnecting pty ready wait: %w", err)
214214
}
215215

216216
defer func() {

agent/reconnectingpty/reconnectingpty.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,8 @@ func (s *ptyState) waitForState(state State) (State, error) {
168168

169169
// waitForStateOrContext blocks until the state or a greater one is reached or
170170
// the provided context ends. If fn is non-nil it will be ran while the lock is
171-
// held and fn's error will replace waitForStateOrContext's error.
171+
// held unless the context ends, and fn's error will replace
172+
// waitForStateOrContext's error.
172173
func (s *ptyState) waitForStateOrContext(ctx context.Context, state State, fn func(state State, err error) error) (State, error) {
173174
nevermind := make(chan struct{})
174175
defer close(nevermind)
@@ -186,14 +187,13 @@ func (s *ptyState) waitForStateOrContext(ctx context.Context, state State, fn fu
186187
for ctx.Err() == nil && state > s.state {
187188
s.cond.Wait()
188189
}
189-
err := s.error
190190
if ctx.Err() != nil {
191-
err = ctx.Err()
191+
return s.state, ctx.Err()
192192
}
193193
if fn != nil {
194-
return s.state, fn(s.state, err)
194+
return s.state, fn(s.state, s.error)
195195
}
196-
return s.state, err
196+
return s.state, s.error
197197
}
198198

199199
// readConnLoop reads messages from conn and writes to ptty as needed. Blocks

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy