Skip to content

bug: suspendProcess() missing signal.Stop causes signal channel leak on Ctrl+Z suspend #1673

@kuishou68

Description

@kuishou68

Bug: suspendProcess() missing signal.Stop causes signal channel leak

In tty_unix.go, the suspendProcess() function registers a channel with signal.Notify to listen for SIGCONT but never calls signal.Stop after the signal is received.

According to Go docs for signal.Notify, callers should use signal.Stop to deregister the channel.

Impact

Each time the user presses Ctrl+Z to suspend the program, a new buffered channel is registered via signal.Notify(c, syscall.SIGCONT) and never deregistered:

  1. Signal channel leak: Every suspend/resume cycle leaves one more registered-but-abandoned channel
  2. Memory leak: Each leaked channel occupies memory until program termination
  3. Future SIGCONT signals attempt delivery to all abandoned channels

Contrast with Correct Usage

handleSignals() in tea.go correctly uses: defer signal.Stop(sig)
listenForResize() in signals_unix.go correctly uses: defer signal.Stop(sig)

But suspendProcess() in tty_unix.go is missing this call.

Fix

Add defer signal.Stop(c) in suspendProcess():

func suspendProcess() {
    c := make(chan os.Signal, 1)
    signal.Notify(c, syscall.SIGCONT)
    defer signal.Stop(c)
    _ = syscall.Kill(0, syscall.SIGTSTP)
    <-c
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions