From 09d427c96983e6052ea71cb55c52775c0ebae208 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Wed, 20 Aug 2025 11:42:33 +1000 Subject: [PATCH] Give webseed request goroutines readable names --- webseed-peer.go | 11 +++++------ webseed/client.go | 13 ++++++++----- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/webseed-peer.go b/webseed-peer.go index a8f3d2ea..d602be49 100644 --- a/webseed-peer.go +++ b/webseed-peer.go @@ -168,11 +168,7 @@ func (ws *webseedPeer) spawnRequest(begin, end RequestIndex, logger *slog.Logger "end", end, "len", end-begin, ) - go func() { - // Detach cost association from webseed update requests routine. - pprof.SetGoroutineLabels(context.Background()) - ws.runRequest(&wsReq) - }() + go ws.sliceProcessor(&wsReq) } func (me *webseedPeer) getRequestKey(wr *webseedRequest) webseedUniqueRequestKey { @@ -214,7 +210,10 @@ func (ws *webseedPeer) readChunksErrorLevel(err error, req *webseedRequest) slog return slog.LevelWarn } -func (ws *webseedPeer) runRequest(webseedRequest *webseedRequest) { +// Reads chunks from the responses for the webseed slice. +func (ws *webseedPeer) sliceProcessor(webseedRequest *webseedRequest) { + // Detach cost association from webseed update requests routine. + pprof.SetGoroutineLabels(context.Background()) locker := ws.locker err := ws.readChunks(webseedRequest) if webseed.PrintDebug && webseedRequest.next < webseedRequest.end { diff --git a/webseed/client.go b/webseed/client.go index acbad8f2..28b49b58 100644 --- a/webseed/client.go +++ b/webseed/client.go @@ -149,14 +149,17 @@ func (ws *Client) StartNewRequest(ctx context.Context, r RequestSpec, debugLogge Body: body, bodyPipe: body, } - go func() { - pprof.SetGoroutineLabels(context.Background()) - err := ws.readRequestPartResponses(ctx, w, requestParts) - panicif.Err(w.CloseWithError(err)) - }() + go ws.requestPartResponsesReader(ctx, w, requestParts) return req } +// Concatenates request part responses and sends them over the pipe. +func (ws *Client) requestPartResponsesReader(ctx context.Context, w *io.PipeWriter, requestParts []requestPart) { + pprof.SetGoroutineLabels(context.Background()) + err := ws.readRequestPartResponses(ctx, w, requestParts) + panicif.Err(w.CloseWithError(err)) +} + type ErrBadResponse struct { Msg string Response *http.Response -- 2.51.0