Skip to content

Commit 83ac118

Browse files
committed
Attempt fixing flake with 'echo test' command
1 parent 56e71c9 commit 83ac118

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

agent/reconnectingpty/buffered.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,16 @@ func (rpty *bufferedReconnectingPTY) Attach(ctx context.Context, connID string,
180180

181181
// Once we are ready, attach the active connection while we hold the mutex.
182182
_, err := rpty.state.waitForStateOrContext(ctx, StateReady, func(state State, err error) error {
183+
// Write any previously stored data for the TTY. Since the command might be
184+
// short-lived and have already exited, make sure we always at least output
185+
// the buffer before returning.
186+
prevBuf := slices.Clone(rpty.circularBuffer.Bytes())
187+
_, err = conn.Write(prevBuf)
188+
if err != nil {
189+
rpty.metrics.WithLabelValues("write").Add(1)
190+
return xerrors.Errorf("write buffer to conn: %w", err)
191+
}
192+
183193
if state != StateReady {
184194
return xerrors.Errorf("reconnecting pty ready wait: %w", err)
185195
}
@@ -194,14 +204,7 @@ func (rpty *bufferedReconnectingPTY) Attach(ctx context.Context, connID string,
194204
rpty.metrics.WithLabelValues("resize").Add(1)
195205
}
196206

197-
// Write any previously stored data for the TTY and store the connection for
198-
// future writes.
199-
prevBuf := slices.Clone(rpty.circularBuffer.Bytes())
200-
_, err = conn.Write(prevBuf)
201-
if err != nil {
202-
rpty.metrics.WithLabelValues("write").Add(1)
203-
return xerrors.Errorf("write buffer to conn: %w", err)
204-
}
207+
// Store the connection for future writes.
205208
rpty.activeConns[connID] = conn
206209

207210
return nil

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