Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion internal/nzbfilesystem/metadata_remote_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ func (mrf *MetadataRemoteFile) OpenFile(ctx context.Context, name string) (bool,
KnownHoles: fileMeta.KnownHoles,
}

fileCtx, cancel := context.WithCancel(ctx)
// Create a metadata-based virtual file handle
virtualFile := &MetadataVirtualFile{
name: name,
Expand All @@ -279,7 +280,8 @@ func (mrf *MetadataRemoteFile) OpenFile(ctx context.Context, name string) (bool,
padRecorder: mrf.padRecorder,
configGetter: mrf.configGetter,
poolManager: mrf.poolManager,
ctx: ctx,
ctx: fileCtx,
cancelCtx: cancel,
maxPrefetch: maxPrefetch,
rcloneCipher: mrf.rcloneCipher,
aesCipher: mrf.aesCipher,
Expand Down Expand Up @@ -799,6 +801,7 @@ type MetadataVirtualFile struct {
configGetter config.ConfigGetter
poolManager pool.Manager // Pool manager for dynamic pool access
ctx context.Context
cancelCtx context.CancelFunc
maxPrefetch int // Maximum segments prefetched ahead of current read position
rcloneCipher *rclone.RcloneCrypt
aesCipher *aes.AesCipher
Expand Down Expand Up @@ -1490,6 +1493,9 @@ func (mvf *MetadataVirtualFile) Seek(offset int64, whence int) (int64, error) {

// Close implements afero.File.Close
func (mvf *MetadataVirtualFile) Close() error {
if mvf.cancelCtx != nil {
mvf.cancelCtx()
}
// Cancel the in-flight reader before taking mvf.mu — a concurrent
// Read can hold the lock for the full segment-download latency.
mvf.interruptCurrentReader()
Expand Down
Loading