Skip to content

Commit 4dc35d3

Browse files
authored
Merge pull request #414 from bane-labs/mem-leak
Fix memory leak
2 parents ead9aab + 5f2b25e commit 4dc35d3

File tree

6 files changed

+13
-15
lines changed

6 files changed

+13
-15
lines changed

cmd/geth/main.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,8 +359,6 @@ func geth(ctx *cli.Context) error {
359359
// it unlocks any requested accounts, and starts the RPC/IPC interfaces and the
360360
// miner.
361361
func startNode(ctx *cli.Context, stack *node.Node, backend ethapi.Backend, isConsole bool) {
362-
debug.Memsize.Add("node", stack)
363-
364362
// Start up the node itself
365363
utils.StartNode(ctx, stack, isConsole)
366364

consensus/dbft/dbft.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -858,6 +858,7 @@ func (c *DBFT) verifyPreBlockCb(b dbft.PreBlock[common.Hash]) bool {
858858
ethBlock := dbftBlock.ToEthBlock()
859859

860860
localPool := c.newLocalPool(parent)
861+
defer localPool.CloseSilently()
861862
errs := localPool.Add(dbftBlock.transactions, false, false)
862863
for i, err := range errs {
863864
if err != nil {
@@ -879,10 +880,9 @@ func (c *DBFT) verifyPreBlockCb(b dbft.PreBlock[common.Hash]) bool {
879880

880881
// Cache processing result for further usage in case if there's no envelopes
881882
// in the block or fallback signing scheme is used.
882-
pre := b.(*PreBlock)
883-
pre.finalState = state
884-
pre.finalReceipts = receipts
885-
pre.finalGASUsed = gasUsed
883+
dbftBlock.finalState = state
884+
dbftBlock.finalReceipts = receipts
885+
dbftBlock.finalGASUsed = gasUsed
886886

887887
return true
888888
}
@@ -1094,6 +1094,7 @@ func (c *DBFT) processPreBlockCb(b dbft.PreBlock[common.Hash]) error {
10941094
return true
10951095
}
10961096
)
1097+
defer localPool.CloseSilently()
10971098
for i := range pre.transactions {
10981099
var isEnvelope = j < len(pre.envelopesData) && pre.envelopesData[j].index == i
10991100
if !isEnvelope || // pre.transactions[i] is not an envelope, use it as-is.

core/txpool/legacypool/legacypool.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -475,15 +475,21 @@ func (pool *LegacyPool) loop() {
475475
}
476476
}
477477

478-
// Close terminates the transaction pool.
479-
func (pool *LegacyPool) Close() error {
478+
// CloseSilently is the same as Close(), but doesn't log. Intended to be used
479+
// for short-lived verification pools (not the main node tx pool).
480+
func (pool *LegacyPool) CloseSilently() {
480481
// Terminate the pool reorger and return
481482
close(pool.reorgShutdownCh)
482483
pool.wg.Wait()
483484

484485
if pool.journal != nil {
485486
pool.journal.close()
486487
}
488+
}
489+
490+
// Close terminates the transaction pool.
491+
func (pool *LegacyPool) Close() error {
492+
pool.CloseSilently()
487493
log.Info("Transaction pool stopped")
488494
return nil
489495
}

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ require (
2525
github.com/fatih/color v1.13.0
2626
github.com/ferranbt/fastssz v0.1.3
2727
github.com/fjl/gencodec v0.0.0-20230517082657-f9840df7b83e
28-
github.com/fjl/memsize v0.0.2
2928
github.com/fsnotify/fsnotify v1.6.0
3029
github.com/gballet/go-libpcsclite v0.0.0-20190607065134-2772fd86a8ff
3130
github.com/gballet/go-verkle v0.1.1-0.20231031103413-a67434b50f46

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,6 @@ github.com/ferranbt/fastssz v0.1.3 h1:ZI+z3JH05h4kgmFXdHuR1aWYsgrg7o+Fw7/NCzM16M
200200
github.com/ferranbt/fastssz v0.1.3/go.mod h1:0Y9TEd/9XuFlh7mskMPfXiI2Dkw4Ddg9EyXt1W7MRvE=
201201
github.com/fjl/gencodec v0.0.0-20230517082657-f9840df7b83e h1:bBLctRc7kr01YGvaDfgLbTwjFNW5jdp5y5rj8XXBHfY=
202202
github.com/fjl/gencodec v0.0.0-20230517082657-f9840df7b83e/go.mod h1:AzA8Lj6YtixmJWL+wkKoBGsLWy9gFrAzi4g+5bCKwpY=
203-
github.com/fjl/memsize v0.0.2 h1:27txuSD9or+NZlnOWdKUxeBzTAUkWCVh+4Gf2dWFOzA=
204-
github.com/fjl/memsize v0.0.2/go.mod h1:VvhXpOYNQvB+uIk2RvXzuaQtkQJzzIx6lSBe1xv7hi0=
205203
github.com/flosch/pongo2 v0.0.0-20190707114632-bbf5a6c351f4/go.mod h1:T9YF2M40nIgbVgp3rreNmTged+9HrbNTIQf1PsaIiTA=
206204
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
207205
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=

internal/debug/flags.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,13 @@ import (
3030
"github.com/ethereum/go-ethereum/log"
3131
"github.com/ethereum/go-ethereum/metrics"
3232
"github.com/ethereum/go-ethereum/metrics/exp"
33-
"github.com/fjl/memsize/memsizeui"
3433
"github.com/mattn/go-colorable"
3534
"github.com/mattn/go-isatty"
3635
"github.com/urfave/cli/v2"
3736
"golang.org/x/exp/slog"
3837
"gopkg.in/natefinch/lumberjack.v2"
3938
)
4039

41-
var Memsize memsizeui.Handler
42-
4340
var (
4441
verbosityFlag = &cli.IntFlag{
4542
Name: "verbosity",
@@ -313,7 +310,6 @@ func StartPProf(address string, withMetrics bool) {
313310
if withMetrics {
314311
exp.Exp(metrics.DefaultRegistry)
315312
}
316-
http.Handle("/memsize/", http.StripPrefix("/memsize", &Memsize))
317313
log.Info("Starting pprof server", "addr", fmt.Sprintf("http://%s/debug/pprof", address))
318314
go func() {
319315
if err := http.ListenAndServe(address, nil); err != nil {

0 commit comments

Comments
 (0)