]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Give webseed request goroutines readable names
authorMatt Joiner <anacrolix@gmail.com>
Wed, 20 Aug 2025 01:42:33 +0000 (11:42 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Thu, 21 Aug 2025 01:42:00 +0000 (11:42 +1000)
webseed-peer.go
webseed/client.go

index a8f3d2eab225c4e150d3edbc33adc78c6c6ef92f..d602be49d7b6e51656291229cc6986b26e1bc4fa 100644 (file)
@@ -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 {
index acbad8f20448d99e308c96d5b6e6bb2312f3cafa..28b49b58e9b571ba308ddfac21f40c115f0d31f3 100644 (file)
@@ -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