← back to Wallco Ai
generator_tick: retry psql on boot-race PG-socket-not-ready (up to ~30s)
6250128bfdbbf697d6be2f1a98143d57810e8941 · 2026-06-01 11:03:41 -0700 · Steve Abrams
Files touched
M scripts/generator_tick.js
Diff
commit 6250128bfdbbf697d6be2f1a98143d57810e8941
Author: Steve Abrams <steve@designerwallcoverings.com>
Date: Mon Jun 1 11:03:41 2026 -0700
generator_tick: retry psql on boot-race PG-socket-not-ready (up to ~30s)
---
scripts/generator_tick.js | 23 ++++++++++++++++++++++-
1 file changed, 22 insertions(+), 1 deletion(-)
diff --git a/scripts/generator_tick.js b/scripts/generator_tick.js
index 6b4f1ec..2d5d032 100644
--- a/scripts/generator_tick.js
+++ b/scripts/generator_tick.js
@@ -26,8 +26,29 @@ const ROOT = path.join(__dirname, '..');
const PSQL_CMD = (process.platform === 'linux')
? `sudo -n -u postgres psql ${DB} -At -q`
: `psql ${DB} -At -q`;
+// Boot-race guard: launchd RunAtLoad fires this tick at login/reboot, often
+// before Postgres has finished opening its unix socket — the first psql() then
+// dies with "connection to server on socket ... failed: No such file or
+// directory" and the whole tick exits non-zero (surfaces as a CNCP failure).
+// Retry ONLY that connection error, with backoff, up to ~30s; real SQL errors
+// still throw immediately.
+function isPgNotReady(err) {
+ const s = `${err && err.stderr || ''}${err && err.message || ''}`;
+ return /connection to server on socket|could not connect to server|the database system is starting up/i.test(s);
+}
function psql(sql) {
- return execSync(PSQL_CMD, { input: sql, encoding: 'utf8' }).trim();
+ const delays = [500, 1000, 2000, 4000, 8000, 15000]; // ~30s total
+ for (let attempt = 0; ; attempt++) {
+ try {
+ return execSync(PSQL_CMD, { input: sql, encoding: 'utf8' }).trim();
+ } catch (err) {
+ if (isPgNotReady(err) && attempt < delays.length) {
+ execSync(`sleep ${delays[attempt] / 1000}`);
+ continue;
+ }
+ throw err;
+ }
+ }
}
function pickRecipe() {
← 5196d88 publish 36 reviewed HC drunk-animals keepers live (settlemen
·
back to Wallco Ai
·
feat(styleguides): Brand Selector admin tool wired to genera 0fbb86a →