🌐 AI搜索 & 代理 主页
Skip to content

Commit 38b7d33

Browse files
Nik SamokhvalovNik Samokhvalov
authored andcommitted
fix(cli): always close pg client in init
- Ensure client.end() runs even when init fails after connect
1 parent 6152995 commit 38b7d33

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

cli/bin/postgres-ai.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,11 @@ program
179179
console.log(`Monitoring user: ${opts.monitoringUser}`);
180180
console.log(`Optional permissions: ${includeOptionalPermissions ? "enabled" : "skipped"}`);
181181

182+
// Use native pg client instead of requiring psql to be installed
183+
const { Client } = require("pg");
184+
const client = new Client(adminConn.clientConfig);
185+
182186
try {
183-
// Use native pg client instead of requiring psql to be installed
184-
const { Client } = require("pg");
185-
const client = new Client(adminConn.clientConfig);
186187
await client.connect();
187188

188189
const roleRes = await client.query("select 1 from pg_catalog.pg_roles where rolname = $1", [
@@ -205,7 +206,6 @@ program
205206
});
206207

207208
const { applied, skippedOptional } = await applyInitPlan({ client, plan });
208-
await client.end();
209209

210210
console.log("✓ init completed");
211211
if (skippedOptional.length > 0) {
@@ -226,6 +226,12 @@ program
226226
}
227227
}
228228
process.exitCode = 1;
229+
} finally {
230+
try {
231+
await client.end();
232+
} catch {
233+
// ignore
234+
}
229235
}
230236
});
231237

0 commit comments

Comments
 (0)