From 193bf5b40c0fe7bad40f1c7fce861f112be435b5 Mon Sep 17 00:00:00 2001 From: gammazero <11790789+gammazero@users.noreply.github.com> Date: Tue, 26 Nov 2024 13:55:28 -1000 Subject: [PATCH] Add debug logging for deduplicated queries --- routing/providerquerymanager/providerquerymanager.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/routing/providerquerymanager/providerquerymanager.go b/routing/providerquerymanager/providerquerymanager.go index d9005020e9..7824167e27 100644 --- a/routing/providerquerymanager/providerquerymanager.go +++ b/routing/providerquerymanager/providerquerymanager.go @@ -193,10 +193,6 @@ func (pqm *ProviderQueryManager) FindProvidersAsync(sessionCtx context.Context, close(ch) span.End() return ch - case <-sessionCtx.Done(): - ch := make(chan peer.AddrInfo) - close(ch) - return ch } // DO NOT select on sessionCtx. We only want to abort here if we're @@ -486,6 +482,13 @@ func (npqm *newProvideQueryMessage) handle(pqm *ProviderQueryManager) { span.AddEvent("NewQuery", trace.WithAttributes(attribute.Stringer("cid", npqm.k))) ctx = trace.ContextWithSpan(ctx, span) + // Use context derived from pqm.ctx here, and not the context from the + // request (npqm.ctx), because this inProgressRequestStatus applies to + // all in-progress requests for the CID (npqm.k). + // + // For tracing, this means that only the span from the first + // request-in-progress for a CID is used, even if there are multiple + // requests for the same CID. requestStatus = &inProgressRequestStatus{ listeners: make(map[chan peer.AddrInfo]struct{}), ctx: ctx, @@ -504,6 +507,7 @@ func (npqm *newProvideQueryMessage) handle(pqm *ProviderQueryManager) { } } else { trace.SpanFromContext(npqm.ctx).AddEvent("JoinQuery", trace.WithAttributes(attribute.Stringer("cid", npqm.k))) + log.Debugf("Joined existing query for cid %s which now has %d queries in progress", npqm.k, len(requestStatus.listeners)+1) } inProgressChan := make(chan peer.AddrInfo) requestStatus.listeners[inProgressChan] = struct{}{}