Skip to content

Commit

Permalink
all: fix potential undefined behavior in timer reset
Browse files Browse the repository at this point in the history
  • Loading branch information
JukLee0ira committed Feb 6, 2025
1 parent bb83243 commit 84b017a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
5 changes: 4 additions & 1 deletion common/countdown/countdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ func (t *CountdownTimer) startTimer(i interface{}, currentRound, highestRound ty
currentRound = info.currentRound
highestRound = info.highestRound
if !timer.Stop() {
<-timer.C
select {
case <-timer.C: // try to drain the channel
default:
}
}
timer.Reset(t.durationHelper.GetTimeoutDuration(currentRound, highestRound))
}
Expand Down
5 changes: 4 additions & 1 deletion eth/filters/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,10 @@ func (api *FilterAPI) GetFilterChanges(id rpc.ID) (interface{}, error) {
if !f.deadline.Stop() {
// timer expired but filter is not yet removed in timeout loop
// receive timer value and reset timer
<-f.deadline.C
select {
case <-f.deadline.C: // try to drain the channel
default:
}
}
f.deadline.Reset(api.timeout)

Expand Down
14 changes: 7 additions & 7 deletions p2p/nat/nat.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"time"

"github.com/XinFinOrg/XDPoSChain/log"
"github.com/jackpal/go-nat-pmp"
natpmp "github.com/jackpal/go-nat-pmp"
)

// An implementation of nat.Interface can map local ports to ports
Expand All @@ -53,12 +53,12 @@ type Interface interface {
// The following formats are currently accepted.
// Note that mechanism names are not case-sensitive.
//
// "" or "none" return nil
// "extip:77.12.33.4" will assume the local machine is reachable on the given IP
// "any" uses the first auto-detected mechanism
// "upnp" uses the Universal Plug and Play protocol
// "pmp" uses NAT-PMP with an auto-detected gateway address
// "pmp:192.168.0.1" uses NAT-PMP with the given gateway address
// "" or "none" return nil
// "extip:77.12.33.4" will assume the local machine is reachable on the given IP
// "any" uses the first auto-detected mechanism
// "upnp" uses the Universal Plug and Play protocol
// "pmp" uses NAT-PMP with an auto-detected gateway address
// "pmp:192.168.0.1" uses NAT-PMP with the given gateway address
func Parse(spec string) (Interface, error) {
var (
parts = strings.SplitN(spec, ":", 2)
Expand Down

0 comments on commit 84b017a

Please sign in to comment.