Skip to content

fix: reset IsActive before RawOutput early return in SpinnerPrinter.Stop() - #764

Merged
MarvinJWendt merged 1 commit into
pterm:masterfrom
bk-simon:fix/spinner-stop-raw-output-goroutine-leak
Feb 25, 2026
Merged

MarvinJWendt merged 1 commit into
pterm:masterfrom
bk-simon:fix/spinner-stop-raw-output-goroutine-leak

Conversation

@bk-simon

@bk-simon bk-simon commented Feb 25, 2026 •

Copy link
Copy Markdown
Contributor

Problem

SpinnerPrinter.Stop() had a combined guard condition:

if !s.IsActive || RawOutput {
    return nil
}
s.IsActive = false

When RawOutput is true (i.e. after calling pterm.DisableStyling()), Stop() returned
immediately without setting IsActive = false. The background goroutine launched by Start()
loops on s.IsActive, so it would keep running indefinitely — a goroutine leak.

This affects any code that calls DisableStyling() (common in tests and CI environments) and
then starts/stops a spinner, as well as direct use of the RawOutput flag.

Fix

Split the condition so IsActive is cleared unconditionally, and only the visual terminal
cleanup is skipped when RawOutput is true:

if !s.IsActive {
    return nil
}
s.IsActive = false    // always reset — stops the background goroutine
if RawOutput {
    return nil        // skip terminal escape sequences only
}

Test

Added TestSpinnerPrinter_StopSetsIsActiveWhenRawOutput which starts a spinner with
DisableStyling() active and asserts that IsActive is false after Stop() returns.

Fixes #763

…top()

When RawOutput is true, Stop() returned early without setting IsActive =
false, leaving the spinner's background goroutine running indefinitely.

Split the combined condition so IsActive is always cleared first, then
return early only to skip the visual terminal cleanup.

Fixes pterm#763
@github-actions github-actions Bot added fix and removed fix labels Feb 25, 2026

@MarvinJWendt MarvinJWendt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for contributing 🚀

@MarvinJWendt
MarvinJWendt enabled auto-merge (squash) February 25, 2026 22:14
@MarvinJWendt
MarvinJWendt merged commit 92adf38 into pterm:master Feb 25, 2026
2 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SpinnerPrinter.Stop() doesn't reset IsActive when RawOutput is true

2 participants