Skip to content

Commit ea22571

Browse files
committed
fix(qbittorrent): avoid overlapping debounced sync timers
1 parent 2f6561c commit ea22571

1 file changed

Lines changed: 4 additions & 7 deletions

File tree

internal/qbittorrent/sync_manager.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2094,25 +2094,22 @@ func (sm *SyncManager) syncAfterModification(instanceID int, client *Client, ope
20942094
}
20952095

20962096
sm.syncDebounceMu.Lock()
2097+
defer sm.syncDebounceMu.Unlock()
2098+
20972099
if sm.debouncedSyncTimers == nil {
20982100
sm.debouncedSyncTimers = make(map[int]*time.Timer)
20992101
}
21002102

21012103
if existing, ok := sm.debouncedSyncTimers[instanceID]; ok {
2102-
if !existing.Stop() {
2103-
// Timer already fired or is running; let it clean up map entry.
2104-
}
2105-
existing.Reset(delay)
2106-
sm.syncDebounceMu.Unlock()
2107-
return
2104+
// Best-effort stop; if the timer has already fired, we let its callback run once.
2105+
existing.Stop()
21082106
}
21092107

21102108
var timer *time.Timer
21112109
timer = time.AfterFunc(delay, func() {
21122110
sm.runDebouncedSync(instanceID, client, operation, timer)
21132111
})
21142112
sm.debouncedSyncTimers[instanceID] = timer
2115-
sm.syncDebounceMu.Unlock()
21162113
}
21172114

21182115
func (sm *SyncManager) runDebouncedSync(instanceID int, client *Client, operation string, timer *time.Timer) {

0 commit comments

Comments
 (0)