Browse Source

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>
pull/7425/head
Chris Lu 4 days ago
committed by GitHub
parent
commit
f234455b76
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 10
      weed/server/filer_server_handlers_read.go

10
weed/server/filer_server_handlers_read.go

@ -1,6 +1,7 @@
package weed_server package weed_server
import ( import (
"context"
"encoding/base64" "encoding/base64"
"encoding/hex" "encoding/hex"
"errors" "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 { if err != nil {
streamCancel()
stats.FilerHandlerCounter.WithLabelValues(stats.ErrorReadStream).Inc() stats.FilerHandlerCounter.WithLabelValues(stats.ErrorReadStream).Inc()
glog.ErrorfCtx(ctx, "failed to prepare stream content %s: %v", r.URL, err) glog.ErrorfCtx(ctx, "failed to prepare stream content %s: %v", r.URL, err)
return nil, err return nil, err
} }
return func(writer io.Writer) error { return func(writer io.Writer) error {
defer streamCancel()
err := streamFn(writer) err := streamFn(writer)
if err != nil { if err != nil {
stats.FilerHandlerCounter.WithLabelValues(stats.ErrorReadStream).Inc() stats.FilerHandlerCounter.WithLabelValues(stats.ErrorReadStream).Inc()

Loading…
Cancel
Save