Skip to content

Commit

Permalink
Fix potential p2p shutdown hangup (#10839)
Browse files Browse the repository at this point in the history
Copy PR #10626 into `main`

Co-authored-by: Mark Holt <135143369+mh0lt@users.noreply.github.com>
  • Loading branch information
yperbasis and mh0lt committed Jun 21, 2024
1 parent 5eb2c2c commit b16049b
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions p2p/discover/v4_udp.go
Original file line number Diff line number Diff line change
Expand Up @@ -606,14 +606,15 @@ func (t *UDPv4) loop() {
return

case p := <-t.addReplyMatcher:
func() {
mutex.Lock()
defer mutex.Unlock()
p.deadline = time.Now().Add(t.replyTimeout)
listUpdate <- plist.PushBack(p)
}()
mutex.Lock()
p.deadline = time.Now().Add(t.replyTimeout)
back := plist.PushBack(p)
mutex.Unlock()
listUpdate <- back

case r := <-t.gotreply:
var removals []*list.Element

func() {
mutex.Lock()
defer mutex.Unlock()
Expand All @@ -629,7 +630,7 @@ func (t *UDPv4) loop() {
if requestDone {
p.errc <- nil
plist.Remove(el)
listUpdate <- el
removals = append(removals, el)
}
// Reset the continuous timeout counter (time drift detection)
contTimeouts = 0
Expand All @@ -638,6 +639,10 @@ func (t *UDPv4) loop() {
r.matched <- matched
}()

for _, el := range removals {
listUpdate <- el
}

case key := <-t.gotkey:
go func() {
if key, err := v4wire.DecodePubkey(crypto.S256(), key); err == nil {
Expand Down

0 comments on commit b16049b

Please sign in to comment.