Skip to content

fix: prevent deadlock in Println/Printf after program shutdown - #1779

Open
Ricardo-M-L wants to merge 2 commits into
charmbracelet:mainfrom
Ricardo-M-L:pr/fix-bubbletea
Open

fix: prevent deadlock in Println/Printf after program shutdown#1779
Ricardo-M-L wants to merge 2 commits into
charmbracelet:mainfrom
Ricardo-M-L:pr/fix-bubbletea

Conversation

@Ricardo-M-L

Copy link
Copy Markdown
Contributor

Fix Program.Println() and Printf() which sent directly to p.msgs without context check, unlike Send(). After shutdown these calls blocked forever, violating the documented safety contract.

Ricardo-M-L added 2 commits August 15, 2026 18:48
Use shutdown(true) instead of cancel() in the panic recovery path.
Previously cancel() only cancelled the program context without
cleaning up the renderer goroutine or closing the cancelReader,
causing resource leaks when the program panics.
Use p.Send() instead of direct channel send so Println and Printf
safely become no-ops once the program has exited, matching the
behavior of Send(), Quit(), and the documented safety contract.
@codecov

codecov Bot commented Aug 25, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 57.72%. Comparing base (351d215) to head (f6a8be0).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
tea.go 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1779      +/-   ##
==========================================
+ Coverage   56.50%   57.72%   +1.22%     
==========================================
  Files          25       25              
  Lines        1315     1339      +24     
==========================================
+ Hits          743      773      +30     
+ Misses        482      476       -6     
  Partials       90       90              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Ricardo-M-L

Copy link
Copy Markdown
Contributor Author

Friendly ping - this PR is small and ready for review whenever there's bandwidth.

What it fixes: Program.Println / Printf send via p.msgs <- directly, which is an unbuffered channel send. Once the program has exited, the eventLoop goroutine that drains p.msgs is gone, so a late Println blocks forever and leaks the calling goroutine (deadlock). The fix routes through p.Send(...), which is already guarded against a closed/stopped program.

Scope: 1 hunk in tea.go. The tutorials/go.mod / go.sum touchups are from a go mod tidy while building the examples - happy to drop them if you'd rather keep this PR to a single file.

Overlap note: this branch also carries the recoverFromGoPanic cleanup fix (p.cancel() -> p.shutdown(true)) which is filed separately as PR 1770. If you'd prefer one PR per fix, I can split that hunk out so this one is only the Println/Printf change.

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