Skip to content
This repository has been archived by the owner on Aug 2, 2021. It is now read-only.

Fix races on Node.Up field by encapsulation #1178

Closed
wants to merge 7 commits into from

Conversation

frncmx
Copy link
Contributor

@frncmx frncmx commented Jan 31, 2019

The Node.Up field was accessed concurrently without "proper" locking.
There was a lock on Network and that was used sometimes to access
the field. Other times the locking was missed and we had
a data race.

Ferenc Szabo added 3 commits January 30, 2019 15:48
I not necessarily agree with the way we wait for event propagation.
But I truly disagree with having duplicated giga comments.
The Node.Up field was accessed concurrently without "proper" locking.
There was a lock on Network and that was used sometimes to access
the  field. Other times the locking was missed and we had
a data race.

For example: ethereum/go-ethereum#18464
The case above was solved, but there were still intermittent/hard to
reproduce races. So let's solve the issue permanently.

resolves: #1146
Making Node.Up field private in 13292ee
broke TestHTTPNetwork and TestHTTPSnapshot. Because the default
UnmarshalJSON does not handle unexported fields.

Important: The fix is partial and not proper to my taste. But I cut
scope as I think the fix may require a change to the current
serialization format. New ticket:
#1177
Copy link

@gluk256 gluk256 left a comment

Choose a reason for hiding this comment

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

excellent job!

Ferenc Szabo added 2 commits January 31, 2019 13:09
It's a good patten to call `defer Unlock()` right after `Lock()` so
(new) error cases won't miss to unlock. Let's get back to that pattern.

The patten was abandoned in 85a79b3,
while fixing a data race. That data race does not exist anymore,
since the Node.Up field got hidden behind its own lock.
@frncmx frncmx changed the title Fix node up races by encapsulation Fix races on Node.Up field by encapsulation Jan 31, 2019
Copy link
Member

@janos janos left a comment

Choose a reason for hiding this comment

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

LGTM. 👍

p2p/simulations/network.go Outdated Show resolved Hide resolved
@frncmx
Copy link
Contributor Author

frncmx commented Jan 31, 2019

opened upstream: ethereum/go-ethereum#18976

@frncmx frncmx closed this Jan 31, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants