fix: limit retries when calling ensureBucket#219
fix: limit retries when calling ensureBucket#219DuncanBetts wants to merge 2 commits intoActivityWatch:masterfrom
Conversation
Greptile SummaryThis PR addresses a resource-accumulation bug where
Confidence Score: 4/5Safe to merge — the fix correctly bounds retry behaviour and eliminates the accumulation bug. The core change is a clear improvement over the previous unbounded retry. One pre-existing latent bug (unhandled promise rejection in
Important Files Changed
Sequence DiagramsequenceDiagram
participant Alarm as heartbeatAlarmListener
participant HB as heartbeat()
participant SH as sendHeartbeat() [retries:3]
participant EB as ensureBucket() [retries:3]
participant AW as AWClient
Alarm->>HB: every 60s
HB->>SH: sendHeartbeat(...)
SH->>AW: client.heartbeat()
AW-->>SH: ❌ fail
SH->>EB: onFailedAttempt → ensureBucket()
EB->>AW: client.ensureBucket() [up to 4 tries]
AW-->>EB: ❌ fail (all 4)
EB-->>SH: reject (⚠️ unhandled — no .catch())
SH->>AW: retry client.heartbeat() [up to 3 more]
AW-->>SH: ❌ fail all retries
SH-->>HB: catch → emitNotification("Unable to send event")
|
I've just added ed1cf63 to ensure the ServiceWorker doesn't crash if ensureBucket retries do fail. |
When wrapping a call to client.ensureBucket with p-retry, passing
forever: truemay have caused issues such as #176 and #60 , for users whose ActivityWatch server is not reachable, since every newheartbeat()calls a newensureBucket(), resulting in 60 concurrent calls an hour after the user opens their browser, and considerably more after a few days.As a side-effect, removes deprecated p-retry
forever.If I understand correctly, every 60s the onAlarm listener; heartbeatAlarmListener is called, which in turn awaits the heartbeat function, which in turn calls sendHeartbeat, which retries 3x and onFailedAttempt calls ensureBucket.
What I haven't thought through fully is whether this means a browser notification to inform the user "Unable to send event to server", "Please ensure that ActivityWatch is running" is never sent, as perhaps in that scenario,
ensureHeartbeatsimply retries forever instead?Replacing
forever: truewith three retries before giving up, as every 60sheartbeatAlarmListenerwill be called regardless, if I understand correctly?