Skip to content

Commit 2a5a2aa

Browse files
cfoustclaude
andcommitted
fix: prevent data race between Terminal.Write and Terminal.State
Terminal.Write (via WriteSync/Parse/setChar) modified the terminal's cell buffer while Terminal.State (via tty.Capture/image.Capture) read it concurrently without synchronization. Fix by holding the struct-level RWMutex in both Write (exclusive) and State (shared read). To avoid deadlocking with Resize—which previously held the lock during the blocking stream.Resize call—release the lock in Resize before performing stream I/O. Co-Authored-By: Claude Opus 4.6 <[email protected]>
1 parent b1ab8db commit 2a5a2aa

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

pkg/mux/screen/terminal.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,14 @@ func (t *Terminal) State() *tty.State {
9696

9797
func (t *Terminal) Resize(size Size) error {
9898
t.Lock()
99-
defer t.Unlock()
10099
if size == t.size {
100+
t.Unlock()
101101
return nil
102102
}
103103

104104
t.size = size
105105
t.terminal.Resize(size)
106+
t.Unlock()
106107

107108
if t.stream != nil {
108109
err := t.stream.Resize(size)

0 commit comments

Comments
 (0)