Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

accounts/abi/bind/backends: fix goroutine leak in unit test #27705

Merged
merged 4 commits into from
Jul 15, 2023

Conversation

yuriechan
Copy link
Contributor

@yuriechan yuriechan commented Jul 12, 2023

Type of change

  • Bug Fix

Description

Properly clean up the running routines with using the Stop method.

Additional details

  • Introduce uber-go/goleak to detect goroutine leaks in tests
  • Run go mod tidy to clean up dependency
  • Used uber-go/goleak to verify the goroutine leak being fixed as pasted below
  • Check for goroutine leaks on all unit tests under accounts/abi/bind/backends/simulated_test.go with goleak.VerifyTestMain
    • use goleak.IgnoreCurrent() option to only detect goroutine that spawned within the unit test code

Related issues

Resolves #23978

Before

=== RUN   TestNewAdjustTimeFail
--- PASS: TestNewAdjustTimeFail (0.00s)
PASS
goleak: Errors on successful test run: found unexpected goroutines:
[Goroutine 48 in state chan receive, with github.com/ethereum/go-ethereum/core/state/snapshot.(*diskLayer).generate on top of the stack:
goroutine 48 [chan receive]:
github.com/ethereum/go-ethereum/core/state/snapshot.(*diskLayer).generate(0x14000122750, 0x140001e2880)
	/Users/y-egawa/opensource/go-ethereum-forked/core/state/snapshot/generate.go:719 +0x454
created by github.com/ethereum/go-ethereum/core/state/snapshot.generateSnapshot
	/Users/y-egawa/opensource/go-ethereum-forked/core/state/snapshot/generate.go:79 +0x2bc

 Goroutine 49 in state select, with github.com/ethereum/go-ethereum/core.(*BlockChain).updateFutureBlocks on top of the stack:
goroutine 49 [select]:
github.com/ethereum/go-ethereum/core.(*BlockChain).updateFutureBlocks(0x14000296800)
	/Users/y-egawa/opensource/go-ethereum-forked/core/blockchain.go:2280 +0xdc
created by github.com/ethereum/go-ethereum/core.NewBlockChain
	/Users/y-egawa/opensource/go-ethereum-forked/core/blockchain.go:409 +0x1a0c

 Goroutine 50 in state chan receive, with github.com/ethereum/go-ethereum/accounts/abi/bind/backends.(*filterBackend).SubscribeNewTxsEvent.func1 on top of the stack:
goroutine 50 [chan receive]:
github.com/ethereum/go-ethereum/accounts/abi/bind/backends.(*filterBackend).SubscribeNewTxsEvent.func1(0x0?)
	/Users/y-egawa/opensource/go-ethereum-forked/accounts/abi/bind/backends/simulated.go:935 +0x20
github.com/ethereum/go-ethereum/event.NewSubscription.func1()
	/Users/y-egawa/opensource/go-ethereum-forked/event/subscription.go:53 +0x64
created by github.com/ethereum/go-ethereum/event.NewSubscription
	/Users/y-egawa/opensource/go-ethereum-forked/event/subscription.go:51 +0xec

 Goroutine 51 in state chan receive, with github.com/ethereum/go-ethereum/accounts/abi/bind/backends.(*filterBackend).SubscribePendingLogsEvent.func1 on top of the stack:
goroutine 51 [chan receive]:
github.com/ethereum/go-ethereum/accounts/abi/bind/backends.(*filterBackend).SubscribePendingLogsEvent.func1(0x0?)
	/Users/y-egawa/opensource/go-ethereum-forked/accounts/abi/bind/backends/simulated.go:935 +0x20
github.com/ethereum/go-ethereum/event.NewSubscription.func1()
	/Users/y-egawa/opensource/go-ethereum-forked/event/subscription.go:53 +0x64
created by github.com/ethereum/go-ethereum/event.NewSubscription
	/Users/y-egawa/opensource/go-ethereum-forked/event/subscription.go:51 +0xec

 Goroutine 52 in state select, with github.com/ethereum/go-ethereum/eth/filters.(*EventSystem).eventLoop on top of the stack:
goroutine 52 [select]:
github.com/ethereum/go-ethereum/eth/filters.(*EventSystem).eventLoop(0x140000bc630)
	/Users/y-egawa/opensource/go-ethereum-forked/eth/filters/filter_system.go:561 +0x28c
created by github.com/ethereum/go-ethereum/eth/filters.NewEventSystem
	/Users/y-egawa/opensource/go-ethereum-forked/eth/filters/filter_system.go:250 +0x3d8
]

After

=== RUN   TestNewAdjustTimeFail
--- PASS: TestNewAdjustTimeFail (0.00s)
PASS

Process finished with the exit code 0

@yuriechan yuriechan closed this Jul 12, 2023
@yuriechan yuriechan reopened this Jul 12, 2023
@yuriechan yuriechan changed the title remove dead code fix(test) : fix goroutine leaks in unit test Jul 12, 2023
@yuriechan yuriechan marked this pull request as ready for review July 12, 2023 16:58
go.sum Outdated Show resolved Hide resolved
Signed-off-by: yuriechan <28754813+yuriechan@users.noreply.github.com>
Signed-off-by: yuriechan <28754813+yuriechan@users.noreply.github.com>
Signed-off-by: yuriechan <28754813+yuriechan@users.noreply.github.com>
Signed-off-by: yuriechan <28754813+yuriechan@users.noreply.github.com>
@holiman holiman changed the title fix(test) : fix goroutine leaks in unit test accounts/abi/bind/backends: fix goroutine leak in unit test Jul 13, 2023
Copy link
Contributor

@holiman holiman left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@holiman holiman added this to the 1.12.1 milestone Jul 13, 2023
@holiman holiman merged commit 00408f7 into ethereum:master Jul 15, 2023
1 check passed
devopsbo3 pushed a commit to HorizenOfficial/go-ethereum that referenced this pull request Nov 10, 2023
devopsbo3 added a commit to HorizenOfficial/go-ethereum that referenced this pull request Nov 10, 2023
devopsbo3 added a commit to HorizenOfficial/go-ethereum that referenced this pull request Nov 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TestNewAdjustTimeFail goroutine leaks
3 participants