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

stop timer before reset #143

Merged
merged 5 commits into from
Jun 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions internal/blocksync/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ func (pool *BlockPool) sendError(err error, peerID types.NodeID) {
}

// for debugging purposes
//
//nolint:unused
func (pool *BlockPool) debug() string {
pool.mtx.Lock()
Expand Down Expand Up @@ -519,6 +520,7 @@ func (peer *bpPeer) resetTimeout() {
if peer.timeout == nil {
peer.timeout = time.AfterFunc(peerTimeout, peer.onTimeout)
} else {
peer.timeout.Stop()
peer.timeout.Reset(peerTimeout)
}
}
Expand Down
1 change: 1 addition & 0 deletions internal/consensus/ticker.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ func (t *timeoutTicker) timeoutRoutine(ctx context.Context) {
// update timeoutInfo and reset timer
// NOTE time.Timer allows duration to be non-positive
ti = newti
t.timer.Stop()
t.timer.Reset(ti.Duration)
t.logger.Debug("Internal state machine timeout scheduled", "duration", ti.Duration, "height", ti.Height, "round", ti.Round, "step", ti.Step)
case <-t.timer.C:
Expand Down
1 change: 1 addition & 0 deletions internal/evidence/reactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ func (r *Reactor) broadcastEvidenceLoop(ctx context.Context, peerID types.NodeID

case <-next.NextWaitChan():
next = next.Next()
timer.Stop()

case <-ctx.Done():
return
Expand Down
4 changes: 3 additions & 1 deletion internal/p2p/conn/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -676,11 +676,13 @@ func newChannel(conn *MConnection, desc ChannelDescriptor) *channel {
// Goroutine-safe
// Times out (and returns false) after defaultSendTimeout
func (ch *channel) sendBytes(bytes []byte) bool {
timer := time.NewTimer(defaultSendTimeout)
defer timer.Stop()
select {
case ch.sendQueue <- bytes:
atomic.AddInt32(&ch.sendQueueSize, 1)
return true
case <-time.After(defaultSendTimeout):
case <-timer.C:
return false
}
}
Expand Down
22 changes: 12 additions & 10 deletions internal/p2p/pex/reactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ type NoPeersAvailableError struct {
}

func (e *NoPeersAvailableError) Error() string {
return fmt.Sprintf("no available peers to send a PEX request to (retrying)")
return fmt.Sprintf("no available peers to send a PEX request to (retrying)")
}

// TODO: We should decide whether we want channel descriptors to be housed
Expand Down Expand Up @@ -114,7 +114,7 @@ type Reactor struct {
channel *p2p.Channel

// Used to signal a restart the node on the application level
restartCh chan struct{}
restartCh chan struct{}
restartNoAvailablePeersWindow time.Duration
}

Expand All @@ -127,14 +127,14 @@ func NewReactor(
selfRemediationConfig *config.SelfRemediationConfig,
) *Reactor {
r := &Reactor{
logger: logger,
peerManager: peerManager,
peerEvents: peerEvents,
availablePeers: make(map[types.NodeID]struct{}),
lastNoAvailablePeers: time.Time{},
requestsSent: make(map[types.NodeID]struct{}),
lastReceivedRequests: make(map[types.NodeID]time.Time),
restartCh: restartCh,
logger: logger,
peerManager: peerManager,
peerEvents: peerEvents,
availablePeers: make(map[types.NodeID]struct{}),
lastNoAvailablePeers: time.Time{},
requestsSent: make(map[types.NodeID]struct{}),
lastReceivedRequests: make(map[types.NodeID]time.Time),
restartCh: restartCh,
restartNoAvailablePeersWindow: time.Duration(selfRemediationConfig.P2pNoPeersRestarWindowSeconds) * time.Second,
}

Expand Down Expand Up @@ -235,6 +235,8 @@ func (r *Reactor) processPexCh(ctx context.Context, pexCh *p2p.Channel) {
// We got a useful result; update the poll timer.
nextPeerRequest = dur
}

timer.Stop()
}
}
}
Expand Down
1 change: 1 addition & 0 deletions internal/p2p/rqueue.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func (q *simpleQueue) run(ctx context.Context) {
pq := make(priorityQueue, 0, q.maxSize)
heap.Init(&pq)
ticker := time.NewTicker(10 * time.Millisecond)
defer ticker.Stop()
// must have a buffer of exactly one because both sides of
// this channel are used in this loop, and simply signals adds
// to the heap
Expand Down