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

Bug: Fix race condition for a read during (*dialScheduler).updateStaticPool() with a previous write on (*dialTask).resolve() #29203

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions p2p/dial.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ type dialScheduler struct {
dialConfig
setupFunc dialSetupFunc
wg sync.WaitGroup
lock sync.Mutex
cancel context.CancelFunc
ctx context.Context
nodesIn chan *enode.Node
Expand Down Expand Up @@ -409,6 +410,8 @@ func (d *dialScheduler) startStaticDials(n int) (started int) {

// updateStaticPool attempts to move the given static dial back into staticPool.
func (d *dialScheduler) updateStaticPool(id enode.ID) {
d.lock.Lock()
defer d.lock.Unlock()
task, ok := d.static[id]
if ok && task.staticPoolIndex < 0 && d.checkDial(task.dest) == nil {
d.addToStaticPool(task)
Expand Down Expand Up @@ -493,6 +496,8 @@ func (t *dialTask) needResolve() bool {
// discovery network with useless queries for nodes that don't exist.
// The backoff delay resets when the node is found.
func (t *dialTask) resolve(d *dialScheduler) bool {
d.lock.Lock()
defer d.lock.Unlock()
if d.resolver == nil {
return false
}
Expand Down