#1794·bubbletea

docs: commands tutorial HTTP snippets omit response body cleanup

Author: dajiaohuangCreated Sep 5, 2026Updated Sep 5, 2026

What happened?

Both HTTP snippets in tutorials/commands/README.md (checkServer and checkSomeUrl) return the status without closing the response body after a successful GET. The runnable tutorials/commands/main.go already defers res.Body.Close(). Readers copying the README therefore miss the cleanup that the corresponding source demonstrates.

Expected: close each successful response body before the command finishes. Actual: a tracking body remains unclosed when either documented command returns. This is a documentation/example ownership error, not a measured memory-leak claim.

How can we reproduce this?

Copy either function from the README. In a small harness, replace http.DefaultTransport with a RoundTripper returning a response with status 200 and this body, retaining a pointer to it:

type trackingBody struct{ closed bool }
func (*trackingBody) Read([]byte) (int, error) { return 0, io.EOF }
func (b *trackingBody) Close() error { b.closed = true; return nil }

Call checkServer() or checkSomeUrl("https://example.invalid/")() and inspect closed after return. Both produce status 200 and closed == false. Adding defer res.Body.Close() after each successful error check makes it true. Restore the original transport after the check; no network request is needed.

I verified both snippets with an in-memory transport and an AST comparison against the README functions. The explicit-close control passed.

Which version of bubbletea are you using?

Main commit 73b6d91ac1c3854dd4af046ab5f9e51d3b3b4290.

Which terminals did you reproduce this with?

Windows Go 1.26.3; a noninteractive HTTP-command harness, no terminal or live server required.

Search

  • I searched open/closed issues, PRs, discussions and file history.

The existing source-only cleanup in commit 22d15ef does not update the two README snippets. Discussion #562 concerns message types, not response cleanup.