Repository navigation
fix(native): ignore terminal calls after Close - #805
Merged
Merged
Conversation
A reconnect frees every terminal from its own goroutine while the frame goroutine may still paint one: setColors since #780 snapshots the views and paints them after releasing the lock, and a frame can hold the shown terminal across the swap. Those calls ran on freed libghostty memory. Close now marks the Terminal closed and every method after it does nothing, returning ErrClosed where it returns an error. The frame that meets ErrClosed is redrawn instead of ending the event loop. Refs #777
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #780, from the concern raised in #777: a light/dark switch during a reconnect could paint terminals that had just been freed.
Cause
terminals.reattachruns on the reconnect goroutine and callsCloseon every terminal. Since #780,setColorssnapshots the views underts.muand paints them after releasing it, so aSetColorscan land on a terminalreattachfreed a moment before. A frame holding the shown terminal across the swap (showthenlayout) had the same exposure, as didonOutput'sWrite.gioterm.Terminaldocuments its methods as safe from several goroutines, butCloseleftv.tdangling and the next call ran on freed libghostty memory.Fix
Closemarks theTerminalclosed. Every method after it does nothing: it returnsErrClosedwhere it returns an error and its zero value otherwise. A secondCloseis a no-op.window.contenttreatsErrClosedas a frame to redraw: the next frame'sshowpicks up the reattached terminal.Tests
TestClosedTerminalIgnoresCallscalls every method on a closed terminal. Before the fix,SetColorsran on the freed terminal and returnednil. After it, the test passes with-race -count=50.native/:gofmt -l .,go vet ./...,go test ./...clean.ErrClosedbranch inwindow.content. Not checked in a real window.Refs #777