vfs: fix vfs cache writeback timer not being stopped when --transfers reached

When processItems filled the last free transfer slot it checked the
next queued item's expiry before the transfer limit, so if that
expiry was still fractionally in the future the timer was reset
instead of stopped. This caused intermittent failures in
TestWriteBackMaxQueue which asserts the timer is stopped once
--transfers uploads are in progress.

Check the transfer limit first so the timer is always stopped when
the transfer limit is reached. The timer is restarted when an upload
finishes so nothing stalls.

Also fix a typo in TestWriteBackMaxQueue which named every queued
item "number1".
This commit is contained in:
Nick Craig-Wood
2026-07-14 14:29:21 +01:00
parent c4d87bd6d4
commit c851d4dec5
2 changed files with 9 additions and 4 deletions
+7 -2
View File
@@ -433,13 +433,18 @@ func (wb *WriteBack) processItems(ctx context.Context) {
}
resetTimer := true
for wbItem := wb._peekItem(); wbItem != nil && time.Until(wbItem.expiry) <= 0; wbItem = wb._peekItem() {
// If reached transfer limit don't restart the timer
for wbItem := wb._peekItem(); wbItem != nil; wbItem = wb._peekItem() {
// If reached transfer limit stop the timer - it will be
// restarted when an upload finishes
if wb.uploads >= fs.GetConfig(wb.ctx).Transfers {
fs.Debugf(wbItem.name, "vfs cache: delaying writeback as --transfers exceeded")
resetTimer = false
break
}
// Stop if the next item hasn't expired yet
if time.Until(wbItem.expiry) > 0 {
break
}
// Pop the item, mark as uploading and start the uploader
wbItem = wb._popItem()
//fs.Debugf(wbItem.name, "uploading = true %p item %p", wbItem, wbItem.item)
+2 -2
View File
@@ -601,10 +601,10 @@ func TestWriteBackMaxQueue(t *testing.T) {
// put toTransfer things in the queue
pis := []*putItem{}
for range toTransfer {
for i := range toTransfer {
pi := newPutItem(t)
pis = append(pis, pi)
wb.Add(0, fmt.Sprintf("number%d", 1), 10, true, pi.put)
wb.Add(0, fmt.Sprintf("number%d", i), 10, true, pi.put)
}
inProgress, queued := wb.Stats()