diff options
| author | Danilo M. <danix@danix.xyz> | 2026-09-15 13:51:47 +0200 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-09-15 13:51:47 +0200 |
| commit | 3bdd5a50c3b8fa0a885dc58a3d0ec64880f95619 (patch) | |
| tree | a339508c3e74d5f4dd7662965c6fd7fe7d251cc9 /internal/notify/service.go | |
| parent | c3c33008bc0aae4971d854e6edcd48144d593bfb (diff) | |
| download | notifyd-3bdd5a50c3b8fa0a885dc58a3d0ec64880f95619.tar.gz notifyd-3bdd5a50c3b8fa0a885dc58a3d0ec64880f95619.zip | |
fix: delete the timer entry on natural expiry
Diffstat (limited to 'internal/notify/service.go')
| -rw-r--r-- | internal/notify/service.go | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/internal/notify/service.go b/internal/notify/service.go index d775aa6..22d7830 100644 --- a/internal/notify/service.go +++ b/internal/notify/service.go @@ -115,9 +115,21 @@ func (s *Service) arm(id uint32, ms int64) { if ms <= 0 { return } - s.timers[id] = time.AfterFunc(time.Duration(ms)*time.Millisecond, func() { - s.store.Expire(id) + var t *time.Timer + t = time.AfterFunc(time.Duration(ms)*time.Millisecond, func() { + s.mu.Lock() + current := s.timers[id] == t + if current { + delete(s.timers, id) + } + s.mu.Unlock() + // Only the current timer may expire the id: a timer left over from a + // replaced notification must not close its successor. + if current { + s.store.Expire(id) + } }) + s.timers[id] = t } func (s *Service) stopTimer(id uint32) { |
