Fix hanging scanner saves (#18368)

Fix various regressions from #18029

* If context is canceled the token is never returned. This will lead to scanner being unable to save and deadlocking.
* Fix backup not being able to get any data (hr empty)
* Reduce backup timeout.
This commit is contained in:
Klaus Post 2023-11-01 09:09:28 -07:00 committed by GitHub
parent ad44fe8d3e
commit 7472818d94
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 12 deletions

View File

@ -985,15 +985,10 @@ func (d *dataUsageCache) save(ctx context.Context, store objectIO, name string)
return ctx.Err()
case maxConcurrentScannerSaves <- struct{}{}:
}
defer func() {
select {
case <-ctx.Done():
case <-maxConcurrentScannerSaves:
}
}()
buf := bytebufferpool.Get()
defer func() {
<-maxConcurrentScannerSaves
buf.Reset()
bytebufferpool.Put(buf)
}()
@ -1002,12 +997,12 @@ func (d *dataUsageCache) save(ctx context.Context, store objectIO, name string)
return err
}
hr, err := hash.NewReader(ctx, bytes.NewReader(buf.Bytes()), int64(buf.Len()), "", "", int64(buf.Len()))
if err != nil {
return err
}
save := func(name string, timeout time.Duration) error {
hr, err := hash.NewReader(ctx, bytes.NewReader(buf.Bytes()), int64(buf.Len()), "", "", int64(buf.Len()))
if err != nil {
return err
}
// Abandon if more than a minute, so we don't hold up scanner.
ctx, cancel := context.WithTimeout(ctx, timeout)
defer cancel()
@ -1022,7 +1017,7 @@ func (d *dataUsageCache) save(ctx context.Context, store objectIO, name string)
}
return err
}
defer save(name+".bkp", 30*time.Second) // Keep a backup as well
defer save(name+".bkp", 5*time.Second) // Keep a backup as well
// drive timeout by default is 2 minutes, we do not need to wait longer.
return save(name, time.Minute)