@@ -518,7 +518,9 @@ func (a *agent) handleReconnectingPTY(ctx context.Context, rawID string, conn ne
518
518
break
519
519
}
520
520
part := buffer [:read ]
521
+ rpty .circularBufferMutex .Lock ()
521
522
_ , err = rpty .circularBuffer .Write (part )
523
+ rpty .circularBufferMutex .Unlock ()
522
524
if err != nil {
523
525
a .logger .Error (ctx , "reconnecting pty write buffer" , slog .Error (err ), slog .F ("id" , id ))
524
526
break
@@ -545,7 +547,9 @@ func (a *agent) handleReconnectingPTY(ctx context.Context, rawID string, conn ne
545
547
a .logger .Error (ctx , "resize reconnecting pty" , slog .F ("id" , id ), slog .Error (err ))
546
548
}
547
549
// Write any previously stored data for the TTY.
550
+ rpty .circularBufferMutex .RLock ()
548
551
_ , err = conn .Write (rpty .circularBuffer .Bytes ())
552
+ rpty .circularBufferMutex .RUnlock ()
549
553
if err != nil {
550
554
a .logger .Warn (ctx , "write reconnecting pty buffer" , slog .F ("id" , id ), slog .Error (err ))
551
555
return
@@ -640,9 +644,10 @@ type reconnectingPTY struct {
640
644
activeConnsMutex sync.Mutex
641
645
activeConns map [string ]net.Conn
642
646
643
- circularBuffer * circbuf.Buffer
644
- timeout * time.Timer
645
- ptty pty.PTY
647
+ circularBuffer * circbuf.Buffer
648
+ circularBufferMutex sync.RWMutex
649
+ timeout * time.Timer
650
+ ptty pty.PTY
646
651
}
647
652
648
653
// Close ends all connections to the reconnecting
0 commit comments