aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lu <chrislusf@users.noreply.github.com>2025-11-01 23:25:56 -0700
committerGitHub <noreply@github.com>2025-11-01 23:25:56 -0700
commitf234455b7653030a20d6cd2b1209e1035a1f87b9 (patch)
tree6100ac8d89467651b84a1cc670b69de3fbd25880
parentb2fd31c08bb5ff42f1798cf60367a3de9f102540 (diff)
downloadseaweedfs-f234455b7653030a20d6cd2b1209e1035a1f87b9.tar.xz
seaweedfs-f234455b7653030a20d6cd2b1209e1035a1f87b9.zip
Filer: separate context for streaming (#7423)
* separate context for streaming * Update weed/server/filer_server_handlers_read.go Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --------- Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
-rw-r--r--weed/server/filer_server_handlers_read.go10
1 files changed, 9 insertions, 1 deletions
diff --git a/weed/server/filer_server_handlers_read.go b/weed/server/filer_server_handlers_read.go
index 92aadcfc8..5f886afa9 100644
--- a/weed/server/filer_server_handlers_read.go
+++ b/weed/server/filer_server_handlers_read.go
@@ -1,6 +1,7 @@
package weed_server
import (
+ "context"
"encoding/base64"
"encoding/hex"
"errors"
@@ -287,13 +288,20 @@ func (fs *FilerServer) GetOrHeadHandler(w http.ResponseWriter, r *http.Request)
}
}
- streamFn, err := filer.PrepareStreamContentWithThrottler(ctx, fs.filer.MasterClient, fs.maybeGetVolumeReadJwtAuthorizationToken, chunks, offset, size, fs.option.DownloadMaxBytesPs)
+ // Use a detached context for streaming so client disconnects/cancellations don't abort volume server operations,
+ // while preserving request-scoped values like tracing IDs.
+ // Matches S3 API behavior. Request context (ctx) is used for metadata operations above.
+ streamCtx, streamCancel := context.WithCancel(context.WithoutCancel(ctx))
+
+ streamFn, err := filer.PrepareStreamContentWithThrottler(streamCtx, fs.filer.MasterClient, fs.maybeGetVolumeReadJwtAuthorizationToken, chunks, offset, size, fs.option.DownloadMaxBytesPs)
if err != nil {
+ streamCancel()
stats.FilerHandlerCounter.WithLabelValues(stats.ErrorReadStream).Inc()
glog.ErrorfCtx(ctx, "failed to prepare stream content %s: %v", r.URL, err)
return nil, err
}
return func(writer io.Writer) error {
+ defer streamCancel()
err := streamFn(writer)
if err != nil {
stats.FilerHandlerCounter.WithLabelValues(stats.ErrorReadStream).Inc()