Skip to content

goroutine leak in new metrics loop() #31244

Closed
@demon-xxi

Description

@demon-xxi

Using go-ethereum library as depednecy in my app for some types parsing. Not running geth rtc..
When upgrading from 1.14.11 to 1.15.2 the goleak started screaming.

Look like this PR #30814 introduced loop() goroutine that always stay active. there is no way to stop it. Also for the code that only refers dependency library for type parsing it's unclear why whole metrics system is initialized now.

System information

go-ethereum version: v1.15.2

Expected behaviour

metrics are not initialized and no extra goroutines spawned

Actual behaviour

meter.go loop() keeps running in goroutine()

Steps to reproduce the behaviour

package main

import (
	"testing"

	"github.com/ethereum/go-ethereum/rpc"
	"go.uber.org/goleak"
)

func TestLeak(t *testing.T) {
	defer goleak.VerifyNone(t)
	println(rpc.LatestBlockNumber)
}

Backtrace

main_test.go:18: found unexpected goroutines:
        [Goroutine 3 in state chan receive, with github.com/ethereum/go-ethereum/metrics.(*meterTicker).loop on top of the stack:
        github.com/ethereum/go-ethereum/metrics.(*meterTicker).loop(0x104783420)
                /Users/demon/.gvm/pkgsets/go1.22.10/global/pkg/mod/github.com/ethereum/go-ethereum@v1.15.2/metrics/meter.go:159 +0x50
        created by github.com/ethereum/go-ethereum/metrics.(*meterTicker).add in goroutine 1
                /Users/demon/.gvm/pkgsets/go1.22.10/global/pkg/mod/github.com/ethereum/go-ethereum@v1.15.2/metrics/meter.go:145 +0xc8

When submitting logs: please submit them as text and not screenshots.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions