Skip to content

Commit

Permalink
don't use the time value from the time.Ticker channel (#2127)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoPolo committed Feb 23, 2023
1 parent 90aedbd commit 6406324
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 8 deletions.
3 changes: 2 additions & 1 deletion p2p/host/pstoremanager/pstoremanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ func (m *PeerstoreManager) background(ctx context.Context, sub event.Subscriptio
// If we reconnect to the peer before we've cleared the information, keep it.
delete(disconnected, p)
}
case now := <-ticker.C:
case <-ticker.C:
now := time.Now()
for p, disconnectTime := range disconnected {
if disconnectTime.Add(m.gracePeriod).Before(now) {
m.pstore.RemovePeer(p)
Expand Down
7 changes: 3 additions & 4 deletions p2p/net/connmgr/decay.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,14 @@ func (d *decayer) process() {

var (
bmp bumpCmd
now time.Time
visit = make(map[*decayingTag]struct{})
)

for {
select {
case now = <-ticker.C:
nn := now
d.lastTick.Store(&nn)
case <-ticker.C:
now := d.clock.Now()
d.lastTick.Store(&now)

d.tagsMu.Lock()
for _, tag := range d.knownTags {
Expand Down
3 changes: 2 additions & 1 deletion p2p/protocol/holepunch/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,8 @@ func (t *tracer) gc() {

for {
select {
case now := <-timer.C:
case <-timer.C:
now := time.Now()
t.mutex.Lock()
for id, entry := range t.peers {
if entry.last.Before(now.Add(-tracerCacheDuration)) {
Expand Down
3 changes: 2 additions & 1 deletion p2p/transport/quicreuse/reuse.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ func (r *reuse) gc() {
select {
case <-r.closeChan:
return
case now := <-ticker.C:
case <-ticker.C:
now := time.Now()
r.mutex.Lock()
for key, conn := range r.global {
if conn.ShouldGarbageCollect(now) {
Expand Down
3 changes: 2 additions & 1 deletion p2p/transport/webtransport/cert_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ func (m *certManager) background(hostKey ic.PrivKey) {
select {
case <-m.ctx.Done():
return
case now := <-t.C:
case <-t.C:
now := m.clock.Now()
m.mx.Lock()
if err := m.rollConfig(hostKey); err != nil {
log.Errorw("rolling config failed", "error", err)
Expand Down

0 comments on commit 6406324

Please sign in to comment.