diff --git a/.github/workflows/go-test-template.yml b/.github/workflows/go-test-template.yml index 1ff1477ef6..87ecc7367b 100644 --- a/.github/workflows/go-test-template.yml +++ b/.github/workflows/go-test-template.yml @@ -146,7 +146,7 @@ jobs: id: coverages run: echo "files=$(find . -type f -name 'module-coverage.txt' | tr -s '\n' ',' | sed 's/,$//')" >> $GITHUB_OUTPUT - name: Upload coverage to Codecov - uses: codecov/codecov-action@54bcd8715eee62d40e33596ef5e8f0f48dbbccab # v4.1.0 + uses: codecov/codecov-action@v4 with: files: ${{ steps.coverages.outputs.files }} env_vars: OS=${{ matrix.os }}, GO=${{ steps.go.outputs.version }} diff --git a/core/routing/query.go b/core/routing/query.go index 0100c70870..30065ccab1 100644 --- a/core/routing/query.go +++ b/core/routing/query.go @@ -49,7 +49,7 @@ type QueryEvent struct { type routingQueryKey struct{} type eventChannel struct { - mu sync.Mutex + mu sync.RWMutex ctx context.Context ch chan<- *QueryEvent } @@ -59,20 +59,22 @@ type eventChannel struct { func (e *eventChannel) waitThenClose() { <-e.ctx.Done() e.mu.Lock() - close(e.ch) - // 1. Signals that we're done. - // 2. Frees memory (in case we end up hanging on to this for a while). - e.ch = nil + if e.ch != nil { + close(e.ch) + // 1. Signals that we're done. + // 2. Frees memory (in case we end up hanging on to this for a while). + e.ch = nil + } e.mu.Unlock() } // send sends an event on the event channel, aborting if either the passed or // the internal context expire. func (e *eventChannel) send(ctx context.Context, ev *QueryEvent) { - e.mu.Lock() + e.mu.RLock() // Closed. if e.ch == nil { - e.mu.Unlock() + e.mu.RUnlock() return } // in case the passed context is unrelated, wait on both. @@ -81,7 +83,7 @@ func (e *eventChannel) send(ctx context.Context, ev *QueryEvent) { case <-e.ctx.Done(): case <-ctx.Done(): } - e.mu.Unlock() + e.mu.RUnlock() } // RegisterForQueryEvents registers a query event channel with the given diff --git a/p2p/host/autorelay/relay_finder.go b/p2p/host/autorelay/relay_finder.go index 7aa6348de8..7c115181f5 100644 --- a/p2p/host/autorelay/relay_finder.go +++ b/p2p/host/autorelay/relay_finder.go @@ -207,7 +207,9 @@ func (rf *relayFinder) background(ctx context.Context) { workTimer := rf.conf.clock.InstantTimer(rf.runScheduledWork(ctx, now, scheduledWork, peerSourceRateLimiter)) defer workTimer.Stop() - go rf.cleanupDisconnectedPeers(ctx) + rf.refCount.Go(func() { + rf.cleanupDisconnectedPeers(ctx) + }) // update addrs on starting the relay finder. rf.updateAddrs() diff --git a/p2p/metricshelper/pool.go b/p2p/metricshelper/pool.go index 3290ed5a03..d1e9193381 100644 --- a/p2p/metricshelper/pool.go +++ b/p2p/metricshelper/pool.go @@ -22,5 +22,6 @@ func PutStringSlice(s *[]string) { if c := cap(*s); c < capacity { panic(fmt.Sprintf("expected a string slice with capacity 8 or greater, got %d", c)) } + clear(*s) stringPool.Put(s) }