webseed-peer.go | 11 +++++------ webseed/client.go | 13 ++++++++----- diff --git a/webseed-peer.go b/webseed-peer.go index a8f3d2eab225c4e150d3edbc33adc78c6c6ef92f..d602be49d7b6e51656291229cc6986b26e1bc4fa 100644 --- a/webseed-peer.go +++ b/webseed-peer.go @@ -168,11 +168,7 @@ "begin", begin, "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 @@ // Error if we aren't also using and/or have peers...? 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 acbad8f20448d99e308c96d5b6e6bb2312f3cafa..28b49b58e9b571ba308ddfac21f40c115f0d31f3 100644 --- a/webseed/client.go +++ b/webseed/client.go @@ -149,12 +149,15 @@ cancel: cancel, 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 {