mirror of
https://github.com/rclone/rclone
synced 2025-01-08 10:26:23 +01:00
union: fix crash when using epff policy - fixes #5000
Before this fix using the epff policy could double close a channel. The fix refactors the code to make that impossible and cancels any running queries when the first query is found.
This commit is contained in:
parent
687a3b1832
commit
6b9e4f939d
@ -17,7 +17,9 @@ func init() {
|
||||
type EpFF struct{}
|
||||
|
||||
func (p *EpFF) epff(ctx context.Context, upstreams []*upstream.Fs, filePath string) (*upstream.Fs, error) {
|
||||
ch := make(chan *upstream.Fs)
|
||||
ch := make(chan *upstream.Fs, len(upstreams))
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
for _, u := range upstreams {
|
||||
u := u // Closure
|
||||
go func() {
|
||||
@ -30,16 +32,10 @@ func (p *EpFF) epff(ctx context.Context, upstreams []*upstream.Fs, filePath stri
|
||||
}()
|
||||
}
|
||||
var u *upstream.Fs
|
||||
for i := 0; i < len(upstreams); i++ {
|
||||
for range upstreams {
|
||||
u = <-ch
|
||||
if u != nil {
|
||||
// close remaining goroutines
|
||||
go func(num int) {
|
||||
defer close(ch)
|
||||
for i := 0; i < num; i++ {
|
||||
<-ch
|
||||
}
|
||||
}(len(upstreams) - 1 - i)
|
||||
break
|
||||
}
|
||||
}
|
||||
if u == nil {
|
||||
|
Loading…
Reference in New Issue
Block a user