Skip to content

runtime: unreachable stopped time.AfterFunc Timers retain their arg payload #75935

@bradfitz

Description

@bradfitz

[Go 1.25.3, macOS+Linux]

Found while debugging a production memory ~leak....

https://go.dev/play/p/dQaXA0miYoX

If you make a time.AfterFunc and Stop it, it doesn't zero out its runtime.timer.arg any interface value because you might Reset it later. But if it's Stopped and the P-heaped timer entry is zombied and the *time.Timer is no longer GC-reachable, that zombied heap entry still has that non-zero arg interface until the timer fires. (or until it becomes the min/max in the heap and cleaned)

In the repro above, it puts it in the middle of the heap, so it's not cleaned.

Can we make runtime.newTimer use AddCleanup or something (on the timeTimer wrapper around the runtime.timer) to zero out the arg field for stopped zombie timers?

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugReportIssues describing a possible bug in the Go implementation.NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.compiler/runtimeIssues related to the Go compiler and/or runtime.

    Type

    No type

    Projects

    Status

    Todo

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions