Skip to content

Commit 7409e7a

Browse files
committed
Do not hold mutex while waiting for state in screen
Holding off on changing this for the buffered version until a potential issue with the pty closing before we add to the map is sorted. I moved the heartbeat start out as well since while we want to wait to start that until after ready, it does not need to be behind the mutex.
1 parent ee30c97 commit 7409e7a

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

agent/reconnectingpty/screen.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,13 @@ func (rpty *screenReconnectingPTY) Attach(ctx context.Context, _ string, conn ne
155155
ctx, cancel := context.WithCancel(ctx)
156156
defer cancel()
157157

158+
state, err := rpty.state.waitForStateOrContext(ctx, StateReady)
159+
if state != StateReady {
160+
return xerrors.Errorf("reconnecting pty ready wait: %w", err)
161+
}
162+
163+
go heartbeat(ctx, rpty.timer, rpty.timeout)
164+
158165
ptty, process, err := rpty.doAttach(ctx, height, width, logger)
159166
if err != nil {
160167
return err
@@ -233,13 +240,6 @@ func (rpty *screenReconnectingPTY) doAttach(ctx context.Context, height, width u
233240
rpty.mutex.Lock()
234241
defer rpty.mutex.Unlock()
235242

236-
state, err := rpty.state.waitForStateOrContext(ctx, StateReady)
237-
if state != StateReady {
238-
return nil, nil, xerrors.Errorf("reconnecting pty ready wait: %w", err)
239-
}
240-
241-
go heartbeat(ctx, rpty.timer, rpty.timeout)
242-
243243
logger.Debug(ctx, "spawning screen client", slog.F("screen_id", rpty.id))
244244

245245
// Wrap the command with screen and tie it to the connection's context.

0 commit comments

Comments
 (0)