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

ethstats: avoid creating subscriptions on background goroutine #22587

Merged
merged 4 commits into from
Mar 30, 2021

Conversation

MariusVanDerWijden
Copy link
Member

No description provided.

ethstats/ethstats.go Outdated Show resolved Hide resolved
if headSub == nil {
log.Info("Stats daemon stopped due to nil head subscription")
return
}
Copy link
Contributor

@fjl fjl Mar 26, 2021

Choose a reason for hiding this comment

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

It's easy to avoid this error by subscribing earlier. If you create the subscriptions in New (or Start) they can never be nil.

Copy link
Contributor

Choose a reason for hiding this comment

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

If they're created in Start, then the deferred Unsubscribe will become "decoupled" from the Subscribe, which is not great either...

Copy link
Contributor

Choose a reason for hiding this comment

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

The Unsubscribe would need to move into Service.Stop then.

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

ethstats/ethstats.go Outdated Show resolved Hide resolved
ethstats/ethstats.go Outdated Show resolved Hide resolved
Co-authored-by: Martin Holst Swende <[email protected]>
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

@fjl fjl merged commit 3faae5d into ethereum:master Mar 30, 2021
@fjl fjl changed the title ethstats: stop loop if subscription fail ethstats: avoid creating subscriptions on background goroutine Mar 30, 2021
atif-konasl pushed a commit to frozeman/pandora-execution-engine that referenced this pull request Oct 15, 2021
…eum#22587)

This fixes an issue where the ethstats service could crash if geth was
started and then immediately stopped due to an internal error. The
cause of the crash was a nil subscription being returned by the backend,
because the background goroutine creating them was scheduled after
the backend had already shut down.

Moving the creation of subscriptions into the Start method, which runs
synchronously during startup of the node, means the returned subscriptions
can never be 'nil'.

Co-authored-by: Felix Lange <[email protected]>
Co-authored-by: Martin Holst Swende <[email protected]>
@MariusVanDerWijden MariusVanDerWijden deleted the ethstats-nil-subscription branch November 30, 2021 15:25
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.

3 participants