diff --git a/striker-ui-api/src/lib/request_handlers/host/createHostConnection.ts b/striker-ui-api/src/lib/request_handlers/host/createHostConnection.ts index 22cd4d5d..84cfc8e7 100644 --- a/striker-ui-api/src/lib/request_handlers/host/createHostConnection.ts +++ b/striker-ui-api/src/lib/request_handlers/host/createHostConnection.ts @@ -10,7 +10,7 @@ import { sub, } from '../../accessModule'; import { sanitize } from '../../sanitize'; -import { rm, stderr, stdoutVar } from '../../shell'; +import { rm, stderr, stdoutVar, systemCall } from '../../shell'; export const createHostConnection: RequestHandler< unknown, @@ -100,17 +100,29 @@ export const createHostConnection: RequestHandler< } try { - const [rawIsPeerDBReachable]: [output: string, returnCode: number] = - await sub('call', { - params: [ - { - shell_call: `PGPASSFILE="${pgpassFilePath}" ${SERVER_PATHS.usr.bin.psql.self} --host ${peerIPAddress} --port ${commonDBPort} --dbname ${commonDBName} --username ${commonDBUser} --no-password --tuples-only --no-align --command "SELECT 1"`, - }, - ], - pre: ['System'], - }); - - isPeerDBReachable = rawIsPeerDBReachable === '1'; + const now = String(Date.now()); + + const rawIsPeerDBReachable = systemCall( + SERVER_PATHS.usr.bin.psql.self, + [ + '--no-align', + '--no-password', + '--tuples-only', + '--command', + `SELECT ${now};`, + '--dbname', + commonDBName, + '--host', + peerIPAddress, + '--port', + String(commonDBPort), + '--username', + commonDBUser, + ], + { env: { PGPASSFILE: pgpassFilePath } }, + ); + + isPeerDBReachable = rawIsPeerDBReachable === now; } catch (subError) { stderr(`Failed to test connection to peer database; CAUSE: ${subError}`); } diff --git a/striker-ui-api/src/lib/shell.ts b/striker-ui-api/src/lib/shell.ts index ffff8a7c..e0a78847 100644 --- a/striker-ui-api/src/lib/shell.ts +++ b/striker-ui-api/src/lib/shell.ts @@ -10,7 +10,7 @@ const print = ( }: { eol?: string; stream?: 'stderr' | 'stdout' } = {}, ) => process[stream].write(`${message}${eol}`); -const systemCall = ( +export const systemCall = ( ...[command, args = [], options = {}]: Parameters ) => { const { error, stderr, stdout } = spawnSync(command, args, {