Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
exchain
nebula
Commits
4b144088
Unverified
Commit
4b144088
authored
Apr 04, 2023
by
OptimismBot
Committed by
GitHub
Apr 04, 2023
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #5341 from ethereum-optimism/fix-p2p-sync-wait
op-node: fix p2p sync client wait group problem
parents
32ad9bdf
2d39a090
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
2 deletions
+19
-2
sync.go
op-node/p2p/sync.go
+19
-2
No files found.
op-node/p2p/sync.go
View file @
4b144088
...
@@ -202,11 +202,18 @@ type SyncClient struct {
...
@@ -202,11 +202,18 @@ type SyncClient struct {
results
chan
syncResult
results
chan
syncResult
receivePayload
receivePayloadFn
// resource context: all peers and mainLoop tasks inherit this, and start shutting down once resCancel() is called.
resCtx
context
.
Context
resCtx
context
.
Context
resCancel
context
.
CancelFunc
resCancel
context
.
CancelFunc
receivePayload
receivePayloadFn
// wait group: wait for the resources to close. Adding to this is only safe if the peersLock is held.
wg
sync
.
WaitGroup
wg
sync
.
WaitGroup
// Don't allow anything to be added to the wait-group while, or after, we are shutting down.
// This is protected by peersLock.
closingPeers
bool
}
}
func
NewSyncClient
(
log
log
.
Logger
,
cfg
*
rollup
.
Config
,
newStream
newStreamFn
,
rcv
receivePayloadFn
,
metrics
SyncClientMetrics
)
*
SyncClient
{
func
NewSyncClient
(
log
log
.
Logger
,
cfg
*
rollup
.
Config
,
newStream
newStreamFn
,
rcv
receivePayloadFn
,
metrics
SyncClientMetrics
)
*
SyncClient
{
...
@@ -239,7 +246,9 @@ func NewSyncClient(log log.Logger, cfg *rollup.Config, newStream newStreamFn, rc
...
@@ -239,7 +246,9 @@ func NewSyncClient(log log.Logger, cfg *rollup.Config, newStream newStreamFn, rc
}
}
func
(
s
*
SyncClient
)
Start
()
{
func
(
s
*
SyncClient
)
Start
()
{
s
.
peersLock
.
Lock
()
s
.
wg
.
Add
(
1
)
s
.
wg
.
Add
(
1
)
s
.
peersLock
.
Unlock
()
go
s
.
mainLoop
()
go
s
.
mainLoop
()
}
}
...
@@ -250,6 +259,9 @@ func (s *SyncClient) AddPeer(id peer.ID) {
...
@@ -250,6 +259,9 @@ func (s *SyncClient) AddPeer(id peer.ID) {
s
.
log
.
Warn
(
"cannot register peer for sync duties, peer was already registered"
,
"peer"
,
id
)
s
.
log
.
Warn
(
"cannot register peer for sync duties, peer was already registered"
,
"peer"
,
id
)
return
return
}
}
if
s
.
closingPeers
{
return
}
s
.
wg
.
Add
(
1
)
s
.
wg
.
Add
(
1
)
// add new peer routine
// add new peer routine
ctx
,
cancel
:=
context
.
WithCancel
(
s
.
resCtx
)
ctx
,
cancel
:=
context
.
WithCancel
(
s
.
resCtx
)
...
@@ -269,7 +281,12 @@ func (s *SyncClient) RemovePeer(id peer.ID) {
...
@@ -269,7 +281,12 @@ func (s *SyncClient) RemovePeer(id peer.ID) {
delete
(
s
.
peers
,
id
)
delete
(
s
.
peers
,
id
)
}
}
// Close will shut down the sync client and all attached work, and block until shutdown is complete.
// This will block if the Start() has not created the main background loop.
func
(
s
*
SyncClient
)
Close
()
error
{
func
(
s
*
SyncClient
)
Close
()
error
{
s
.
peersLock
.
Lock
()
s
.
closingPeers
=
true
s
.
peersLock
.
Unlock
()
s
.
resCancel
()
s
.
resCancel
()
s
.
wg
.
Wait
()
s
.
wg
.
Wait
()
return
nil
return
nil
...
...
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