Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
fc01a7ce
Unverified
Commit
fc01a7ce
authored
Dec 14, 2021
by
Felföldi Zsolt
Committed by
GitHub
Dec 14, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
les/vflux/client, p2p/nodestate: fix data races (#24058)
Fixes #23848
parent
155795be
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
6 deletions
+42
-6
serverpool_test.go
les/vflux/client/serverpool_test.go
+34
-5
nodestate.go
p2p/nodestate/nodestate.go
+8
-1
No files found.
les/vflux/client/serverpool_test.go
View file @
fc01a7ce
...
@@ -63,7 +63,11 @@ type ServerPoolTest struct {
...
@@ -63,7 +63,11 @@ type ServerPoolTest struct {
trusted
[]
string
trusted
[]
string
waitCount
,
waitEnded
int32
waitCount
,
waitEnded
int32
lock
sync
.
Mutex
// preNegLock protects the cycle counter, testNodes list and its connected field
// (accessed from both the main thread and the preNeg callback)
preNegLock
sync
.
Mutex
queryWg
*
sync
.
WaitGroup
// a new wait group is created each time the simulation is started
stopping
bool
// stopping avoid callind queryWg.Add after queryWg.Wait
cycle
,
conn
,
servedConn
int
cycle
,
conn
,
servedConn
int
serviceCycles
,
dialCount
int
serviceCycles
,
dialCount
int
...
@@ -111,13 +115,21 @@ func (s *ServerPoolTest) addTrusted(i int) {
...
@@ -111,13 +115,21 @@ func (s *ServerPoolTest) addTrusted(i int) {
func
(
s
*
ServerPoolTest
)
start
()
{
func
(
s
*
ServerPoolTest
)
start
()
{
var
testQuery
QueryFunc
var
testQuery
QueryFunc
s
.
queryWg
=
new
(
sync
.
WaitGroup
)
if
s
.
preNeg
{
if
s
.
preNeg
{
testQuery
=
func
(
node
*
enode
.
Node
)
int
{
testQuery
=
func
(
node
*
enode
.
Node
)
int
{
s
.
preNegLock
.
Lock
()
if
s
.
stopping
{
s
.
preNegLock
.
Unlock
()
return
0
}
s
.
queryWg
.
Add
(
1
)
idx
:=
testNodeIndex
(
node
.
ID
())
idx
:=
testNodeIndex
(
node
.
ID
())
n
:=
&
s
.
testNodes
[
idx
]
n
:=
&
s
.
testNodes
[
idx
]
s
.
lock
.
Lock
()
canConnect
:=
!
n
.
connected
&&
n
.
connectCycles
!=
0
&&
s
.
cycle
>=
n
.
nextConnCycle
canConnect
:=
!
n
.
connected
&&
n
.
connectCycles
!=
0
&&
s
.
cycle
>=
n
.
nextConnCycle
s
.
lock
.
Unlock
()
s
.
preNegLock
.
Unlock
()
defer
s
.
queryWg
.
Done
()
if
s
.
preNegFail
{
if
s
.
preNegFail
{
// simulate a scenario where UDP queries never work
// simulate a scenario where UDP queries never work
s
.
beginWait
()
s
.
beginWait
()
...
@@ -181,11 +193,20 @@ func (s *ServerPoolTest) start() {
...
@@ -181,11 +193,20 @@ func (s *ServerPoolTest) start() {
}
}
func
(
s
*
ServerPoolTest
)
stop
()
{
func
(
s
*
ServerPoolTest
)
stop
()
{
// disable further queries and wait if one is currently running
s
.
preNegLock
.
Lock
()
s
.
stopping
=
true
s
.
preNegLock
.
Unlock
()
s
.
queryWg
.
Wait
()
quit
:=
make
(
chan
struct
{})
quit
:=
make
(
chan
struct
{})
s
.
quit
<-
quit
s
.
quit
<-
quit
<-
quit
<-
quit
s
.
sp
.
Stop
()
s
.
sp
.
Stop
()
s
.
spi
.
Close
()
s
.
spi
.
Close
()
s
.
preNegLock
.
Lock
()
s
.
stopping
=
false
s
.
preNegLock
.
Unlock
()
for
i
:=
range
s
.
testNodes
{
for
i
:=
range
s
.
testNodes
{
n
:=
&
s
.
testNodes
[
i
]
n
:=
&
s
.
testNodes
[
i
]
if
n
.
connected
{
if
n
.
connected
{
...
@@ -205,7 +226,9 @@ func (s *ServerPoolTest) run() {
...
@@ -205,7 +226,9 @@ func (s *ServerPoolTest) run() {
n
:=
&
s
.
testNodes
[
idx
]
n
:=
&
s
.
testNodes
[
idx
]
s
.
sp
.
UnregisterNode
(
n
.
node
)
s
.
sp
.
UnregisterNode
(
n
.
node
)
n
.
totalConn
+=
s
.
cycle
n
.
totalConn
+=
s
.
cycle
s
.
preNegLock
.
Lock
()
n
.
connected
=
false
n
.
connected
=
false
s
.
preNegLock
.
Unlock
()
n
.
node
=
nil
n
.
node
=
nil
s
.
conn
--
s
.
conn
--
if
n
.
service
{
if
n
.
service
{
...
@@ -230,7 +253,9 @@ func (s *ServerPoolTest) run() {
...
@@ -230,7 +253,9 @@ func (s *ServerPoolTest) run() {
s
.
servedConn
++
s
.
servedConn
++
}
}
n
.
totalConn
-=
s
.
cycle
n
.
totalConn
-=
s
.
cycle
s
.
preNegLock
.
Lock
()
n
.
connected
=
true
n
.
connected
=
true
s
.
preNegLock
.
Unlock
()
dc
:=
s
.
cycle
+
n
.
connectCycles
dc
:=
s
.
cycle
+
n
.
connectCycles
s
.
disconnect
[
dc
]
=
append
(
s
.
disconnect
[
dc
],
idx
)
s
.
disconnect
[
dc
]
=
append
(
s
.
disconnect
[
dc
],
idx
)
n
.
node
=
dial
n
.
node
=
dial
...
@@ -242,9 +267,9 @@ func (s *ServerPoolTest) run() {
...
@@ -242,9 +267,9 @@ func (s *ServerPoolTest) run() {
}
}
s
.
serviceCycles
+=
s
.
servedConn
s
.
serviceCycles
+=
s
.
servedConn
s
.
clock
.
Run
(
time
.
Second
)
s
.
clock
.
Run
(
time
.
Second
)
s
.
l
ock
.
Lock
()
s
.
preNegL
ock
.
Lock
()
s
.
cycle
++
s
.
cycle
++
s
.
l
ock
.
Unlock
()
s
.
preNegL
ock
.
Unlock
()
}
}
}
}
...
@@ -255,11 +280,13 @@ func (s *ServerPoolTest) setNodes(count, conn, wait int, service, trusted bool)
...
@@ -255,11 +280,13 @@ func (s *ServerPoolTest) setNodes(count, conn, wait int, service, trusted bool)
idx
=
rand
.
Intn
(
spTestNodes
)
idx
=
rand
.
Intn
(
spTestNodes
)
}
}
res
=
append
(
res
,
idx
)
res
=
append
(
res
,
idx
)
s
.
preNegLock
.
Lock
()
s
.
testNodes
[
idx
]
=
spTestNode
{
s
.
testNodes
[
idx
]
=
spTestNode
{
connectCycles
:
conn
,
connectCycles
:
conn
,
waitCycles
:
wait
,
waitCycles
:
wait
,
service
:
service
,
service
:
service
,
}
}
s
.
preNegLock
.
Unlock
()
if
trusted
{
if
trusted
{
s
.
addTrusted
(
idx
)
s
.
addTrusted
(
idx
)
}
}
...
@@ -273,7 +300,9 @@ func (s *ServerPoolTest) resetNodes() {
...
@@ -273,7 +300,9 @@ func (s *ServerPoolTest) resetNodes() {
n
.
totalConn
+=
s
.
cycle
n
.
totalConn
+=
s
.
cycle
s
.
sp
.
UnregisterNode
(
n
.
node
)
s
.
sp
.
UnregisterNode
(
n
.
node
)
}
}
s
.
preNegLock
.
Lock
()
s
.
testNodes
[
i
]
=
spTestNode
{
totalConn
:
n
.
totalConn
}
s
.
testNodes
[
i
]
=
spTestNode
{
totalConn
:
n
.
totalConn
}
s
.
preNegLock
.
Unlock
()
}
}
s
.
conn
,
s
.
servedConn
=
0
,
0
s
.
conn
,
s
.
servedConn
=
0
,
0
s
.
disconnect
=
make
(
map
[
int
][]
int
)
s
.
disconnect
=
make
(
map
[
int
][]
int
)
...
...
p2p/nodestate/nodestate.go
View file @
fc01a7ce
...
@@ -808,7 +808,14 @@ func (ns *NodeStateMachine) addTimeout(n *enode.Node, mask bitMask, timeout time
...
@@ -808,7 +808,14 @@ func (ns *NodeStateMachine) addTimeout(n *enode.Node, mask bitMask, timeout time
ns
.
removeTimeouts
(
node
,
mask
)
ns
.
removeTimeouts
(
node
,
mask
)
t
:=
&
nodeStateTimeout
{
mask
:
mask
}
t
:=
&
nodeStateTimeout
{
mask
:
mask
}
t
.
timer
=
ns
.
clock
.
AfterFunc
(
timeout
,
func
()
{
t
.
timer
=
ns
.
clock
.
AfterFunc
(
timeout
,
func
()
{
ns
.
SetState
(
n
,
Flags
{},
Flags
{
mask
:
t
.
mask
,
setup
:
ns
.
setup
},
0
)
ns
.
lock
.
Lock
()
defer
ns
.
lock
.
Unlock
()
if
!
ns
.
opStart
()
{
return
}
ns
.
setState
(
n
,
Flags
{},
Flags
{
mask
:
t
.
mask
,
setup
:
ns
.
setup
},
0
)
ns
.
opFinish
()
})
})
node
.
timeouts
=
append
(
node
.
timeouts
,
t
)
node
.
timeouts
=
append
(
node
.
timeouts
,
t
)
if
mask
&
ns
.
saveFlags
!=
0
{
if
mask
&
ns
.
saveFlags
!=
0
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment