@vibe-cafe/vibe-usage 0.7.14 → 0.7.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/daemon.js +18 -3
package/package.json
CHANGED
package/src/daemon.js
CHANGED
|
@@ -22,16 +22,31 @@ export async function runDaemon() {
|
|
|
22
22
|
|
|
23
23
|
log('daemon started (sync every 30m, Ctrl+C to stop)');
|
|
24
24
|
|
|
25
|
+
// Why we don't exit on the first 401: launchd KeepAlive / systemd
|
|
26
|
+
// Restart=on-failure relaunch in ~10s, which used to turn a single bad/
|
|
27
|
+
// revoked key into ~360 ingest-401s per hour per machine. Sleeping a full
|
|
28
|
+
// INTERVAL between auth retries collapses that storm to the daemon's normal
|
|
29
|
+
// 30m cadence; only after MAX_AUTH_FAILURES consecutive 401s do we hand
|
|
30
|
+
// off to the supervisor, which by then can't relaunch fast enough to matter.
|
|
31
|
+
const MAX_AUTH_FAILURES = 5;
|
|
32
|
+
let consecutiveAuthFailures = 0;
|
|
33
|
+
|
|
25
34
|
// eslint-disable-next-line no-constant-condition
|
|
26
35
|
while (true) {
|
|
27
36
|
try {
|
|
28
37
|
await runSync({ throws: true, quiet: true });
|
|
38
|
+
consecutiveAuthFailures = 0;
|
|
29
39
|
} catch (err) {
|
|
30
40
|
if (err.message === 'UNAUTHORIZED') {
|
|
31
|
-
|
|
32
|
-
|
|
41
|
+
consecutiveAuthFailures++;
|
|
42
|
+
if (consecutiveAuthFailures >= MAX_AUTH_FAILURES) {
|
|
43
|
+
log(`API key invalid for ${MAX_AUTH_FAILURES} consecutive syncs, exiting.`);
|
|
44
|
+
process.exit(1);
|
|
45
|
+
}
|
|
46
|
+
log(`API key invalid (attempt ${consecutiveAuthFailures}/${MAX_AUTH_FAILURES}), retrying in 30m.`);
|
|
47
|
+
} else {
|
|
48
|
+
log(`sync error: ${err.message}`);
|
|
33
49
|
}
|
|
34
|
-
log(`sync error: ${err.message}`);
|
|
35
50
|
}
|
|
36
51
|
await sleep(INTERVAL);
|
|
37
52
|
}
|