Skip to content

fix: avoid blocking Program.Print methods after exit - #1758

Open
Ricardo-M-L wants to merge 1 commit into
charmbracelet:mainfrom
Ricardo-M-L:fix/program-print-after-exit
Open

fix: avoid blocking Program.Print methods after exit#1758
Ricardo-M-L wants to merge 1 commit into
charmbracelet:mainfrom
Ricardo-M-L:fix/program-print-after-exit

Conversation

@Ricardo-M-L

Copy link
Copy Markdown
Contributor

Problem

Program.Println and Program.Printf send directly to the unbuffered p.msgs channel. After Run returns, the event loop is gone and there is no receiver, so either method blocks forever when called during late goroutine cleanup or after program shutdown.

This differs from Program.Send, which already documents and implements post-exit calls as a no-op by selecting on the program context.

Fix

Route both print methods through Program.Send and document the post-exit behavior. Printing while the program is running is unchanged; after exit the methods now return instead of leaking or deadlocking a goroutine.

The regression test runs a program to completion and verifies both methods return. Against main, each call remains blocked on p.msgs.

Validation

  • go test -run TestProgramPrintAfterExit -count=100 ./...

  • go test -race -run TestProgramPrintAfterExit -count=50 ./...

  • go test ./...

  • go test -race -count=1 ./...

  • go vet ./...

  • go test ./... in examples/

  • go run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.9.0 run

  • git diff --check

  • I have read CONTRIBUTING.md.

@Ricardo-M-L

Copy link
Copy Markdown
Contributor Author

Friendly ping — this is a small, isolated fix with no behavioral changes beyond preventing deadlocks on Program.Print after exit. Happy to address any concerns or split if needed. Would love to see this land in the next release!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant