fix(net): close of closed channel (#7529)

This commit is contained in:
j2rong4cn 2024-11-21 22:39:14 +08:00 committed by GitHub
parent 25c5e075a9
commit 4c0cffd29b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -4,7 +4,6 @@ import (
"bytes" "bytes"
"context" "context"
"fmt" "fmt"
"github.com/alist-org/alist/v3/pkg/utils"
"io" "io"
"math" "math"
"net/http" "net/http"
@ -13,6 +12,8 @@ import (
"sync" "sync"
"time" "time"
"github.com/alist-org/alist/v3/pkg/utils"
"github.com/alist-org/alist/v3/pkg/http_range" "github.com/alist-org/alist/v3/pkg/http_range"
"github.com/aws/aws-sdk-go/aws/awsutil" "github.com/aws/aws-sdk-go/aws/awsutil"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
@ -168,6 +169,9 @@ func (d *downloader) sendChunkTask() *chunk {
// when the final reader Close, we interrupt // when the final reader Close, we interrupt
func (d *downloader) interrupt() error { func (d *downloader) interrupt() error {
if d.chunkChannel == nil {
return nil
}
d.cancel() d.cancel()
if d.written != d.params.Range.Length { if d.written != d.params.Range.Length {
log.Debugf("Downloader interrupt before finish") log.Debugf("Downloader interrupt before finish")
@ -177,6 +181,7 @@ func (d *downloader) interrupt() error {
} }
defer func() { defer func() {
close(d.chunkChannel) close(d.chunkChannel)
d.chunkChannel = nil
for _, buf := range d.bufs { for _, buf := range d.bufs {
buf.Close() buf.Close()
} }