Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

fix(pam): rename backendPid to nativeConnectionId, add mysql metadata error handler

bernie-gac0a5bc4a9e3
diff --git a/backend/src/ee/services/pam-web-access/mysql/pam-mysql-connection-controller.ts b/backend/src/ee/services/pam-web-access/mysql/pam-mysql-connection-controller.ts
index 20e0ff0725..1c1fd3c66b 100644
--- a/backend/src/ee/services/pam-web-access/mysql/pam-mysql-connection-controller.ts
+++ b/backend/src/ee/services/pam-web-access/mysql/pam-mysql-connection-controller.ts
@@ -45,7 +45,7 @@ export const createMysqlConnectionController = async (params: ControllerParams):
});
const [pidRows] = await conn.execute<mysql.RowDataPacket[]>("SELECT CONNECTION_ID() AS pid");
- const backendPid = (pidRows[0]?.pid as number) ?? null;
+ const nativeConnectionId = (pidRows[0]?.pid as number) ?? null;
await conn.query(`SET SESSION max_execution_time = 30000, sql_select_limit = ${MAX_ROWS + 1}`);
@@ -84,7 +84,7 @@ export const createMysqlConnectionController = async (params: ControllerParams):
};
const cancelRunningQuery = async () => {
- if (!backendPid) return;
+ if (!nativeConnectionId) return;
let cancelConn: mysql.Connection | null = null;
try {
cancelConn = await mysql.createConnection({
@@ -96,7 +96,7 @@ export const createMysqlConnectionController = async (params: ControllerParams):
connectTimeout: 5_000
});
cancelConn.on("error" as never, () => {});
- await cancelConn.execute("KILL QUERY ?", [backendPid]);
+ await cancelConn.execute("KILL QUERY ?", [nativeConnectionId]);
} catch (err) {
logger.debug(err, `Failed to cancel MySQL query [sessionId=${sessionId}] [connectionId=${connectionId}]`);
} finally {
@@ -275,7 +275,7 @@ export const createMysqlConnectionController = async (params: ControllerParams):
return {
connectionId,
- backendPid,
+ nativeConnectionId,
handleMessage,
dispose,
isDisposing: () => disposing
diff --git a/backend/src/ee/services/pam-web-access/mysql/pam-mysql-metadata.ts b/backend/src/ee/services/pam-web-access/mysql/pam-mysql-metadata.ts
index a39ad7c73a..9325f7aad6 100644
--- a/backend/src/ee/services/pam-web-access/mysql/pam-mysql-metadata.ts
+++ b/backend/src/ee/services/pam-web-access/mysql/pam-mysql-metadata.ts
@@ -15,6 +15,9 @@ const buildConnection = async ({ relayPort, username, database }: OneShotOptions
connectTimeout: 10_000,
multipleStatements: false
});
+ conn.on("error" as never, (err: Error) => {
+ logger.debug(err, "one-shot mysql connection error");
+ });
return conn;
};
diff --git a/backend/src/ee/services/pam-web-access/pam-data-explorer-session-handler.ts b/backend/src/ee/services/pam-web-access/pam-data-explorer-session-handler.ts
index 434a21c643..23a0be3363 100644
--- a/backend/src/ee/services/pam-web-access/pam-data-explorer-session-handler.ts
+++ b/backend/src/ee/services/pam-web-access/pam-data-explorer-session-handler.ts
@@ -123,7 +123,7 @@ export const createDataExplorerSessionHandler = (config: TDataExplorerDialectCon
type: DataExplorerServerMessageType.ConnectionOpened,
id: requestId,
connectionId,
- backendPid: controller.backendPid
+ nativeConnectionId: controller.nativeConnectionId
});
} catch (err) {
controllers.delete(connectionId);
diff --git a/backend/src/ee/services/pam-web-access/pam-data-explorer-ws-types.ts b/backend/src/ee/services/pam-web-access/pam-data-explorer-ws-types.ts
index 3233501df0..0486669c31 100644
--- a/backend/src/ee/services/pam-web-access/pam-data-explorer-ws-types.ts
+++ b/backend/src/ee/services/pam-web-access/pam-data-explorer-ws-types.ts
@@ -138,7 +138,7 @@ const ErrorResponseSchema = CorrelatedBaseSchema.extend({
const ConnectionOpenedResponseSchema = CorrelatedBaseSchema.extend({
type: z.literal(DataExplorerServerMessageType.ConnectionOpened),
connectionId: z.string().uuid(),
- backendPid: z.number().nullable()
+ nativeConnectionId: z.number().nullable()
});
const ConnectionOpenFailedResponseSchema = CorrelatedBaseSchema.extend({
@@ -175,7 +175,7 @@ export type TTabScopedMessage = Extract<
export type TConnectionController = {
connectionId: string;
- backendPid: number | null;
+ nativeConnectionId: number | null;
handleMessage: (msg: TTabScopedMessage) => void;
dispose: () => void;
isDisposing: () => boolean;
diff --git a/backend/src/ee/services/pam-web-access/postgres/pam-postgres-connection-controller.ts b/backend/src/ee/services/pam-web-access/postgres/pam-postgres-connection-controller.ts
index 343bf030c3..e99a60d89d 100644
--- a/backend/src/ee/services/pam-web-access/postgres/pam-postgres-connection-controller.ts
+++ b/backend/src/ee/services/pam-web-access/postgres/pam-postgres-connection-controller.ts
@@ -42,7 +42,7 @@ export const createPostgresConnectionController = async (params: ControllerParam
await pgClient.connect();
const { rows: pidRows } = await pgClient.query<{ pid: number }>("SELECT pg_backend_pid() AS pid");
- const backendPid = pidRows[0]?.pid ?? null;
+ const nativeConnectionId = pidRows[0]?.pid ?? null;
let isInTransaction = false;
let disposing = false;
@@ -70,7 +70,7 @@ export const createPostgresConnectionController = async (params: ControllerParam
};
const cancelRunningQuery = async () => {
- if (!backendPid) return;
+ if (!nativeConnectionId) return;
const cancelClient = new pg.Client({
host: "localhost",
port: relayPort,
@@ -85,7 +85,7 @@ export const createPostgresConnectionController = async (params: ControllerParam
});
try {
await cancelClient.connect();
- await cancelClient.query("SELECT pg_cancel_backend($1)", [backendPid]);
+ await cancelClient.query("SELECT pg_cancel_backend($1)", [nativeConnectionId]);
} catch (err) {
logger.debug(err, `Failed to cancel backend query [sessionId=${sessionId}] [connectionId=${connectionId}]`);
} finally {
@@ -248,7 +248,7 @@ export const createPostgresConnectionController = async (params: ControllerParam
return {
connectionId,
- backendPid,
+ nativeConnectionId,
handleMessage,
dispose,
isDisposing: () => disposing
diff --git a/frontend/src/pages/pam/PamDataExplorerPage/data-explorer-types.ts b/frontend/src/pages/pam/PamDataExplorerPage/data-explorer-types.ts
index d0e4e36aa5..f3483a21ee 100644
--- a/frontend/src/pages/pam/PamDataExplorerPage/data-explorer-types.ts
+++ b/frontend/src/pages/pam/PamDataExplorerPage/data-explorer-types.ts
@@ -46,7 +46,7 @@ export type DataExplorerServerMessage =
detail?: string;
hint?: string;
}
- | { type: "connection-opened"; id: string; connectionId: string; backendPid: number | null }
+ | { type: "connection-opened"; id: string; connectionId: string; nativeConnectionId: number | null }
| { type: "connection-open-failed"; id: string; error: string }
| { type: "connection-closed"; connectionId: string; reason: string }
| { type: "ready" }
diff --git a/frontend/src/pages/pam/PamDataExplorerPage/use-data-explorer-session.ts b/frontend/src/pages/pam/PamDataExplorerPage/use-data-explorer-session.ts
index f54bc65577..029242e962 100644
--- a/frontend/src/pages/pam/PamDataExplorerPage/use-data-explorer-session.ts
+++ b/frontend/src/pages/pam/PamDataExplorerPage/use-data-explorer-session.ts
@@ -340,14 +340,14 @@ export const useDataExplorerSession = ({
const openConnection = useCallback(async (): Promise<{
connectionId: string;
- backendPid: number | null;
+ nativeConnectionId: number | null;
}> => {
const resp = await sendRequest<
Extract<DataExplorerServerMessage, { type: "connection-opened" }>
>({
type: "open-connection"
});
- return { connectionId: resp.connectionId, backendPid: resp.backendPid };
+ return { connectionId: resp.connectionId, nativeConnectionId: resp.nativeConnectionId };
}, [sendRequest]);
const closeConnection = useCallback((connectionId: string): void => {
diff --git a/frontend/src/pages/pam/PamDataExplorerPage/use-query-tabs.ts b/frontend/src/pages/pam/PamDataExplorerPage/use-query-tabs.ts
index 5d488a827a..3c9804f8ee 100644
--- a/frontend/src/pages/pam/PamDataExplorerPage/use-query-tabs.ts
+++ b/frontend/src/pages/pam/PamDataExplorerPage/use-query-tabs.ts
@@ -7,7 +7,7 @@ import type { TableDetail } from "./data-explorer-types";
type TabBase = {
id: string;
connectionId: string;
- backendPid: number | null;
+ nativeConnectionId: number | null;
isInTransaction: boolean;
lastFocusedAt: number;
isDead?: boolean;
@@ -33,7 +33,7 @@ type Tab = BrowseTab | QueryTab;
const MAX_TABS = 20;
type UseQueryTabsOptions = {
- openConnection: () => Promise<{ connectionId: string; backendPid: number | null }>;
+ openConnection: () => Promise<{ connectionId: string; nativeConnectionId: number | null }>;
closeConnection: (connectionId: string) => void;
fetchTableDetail: (
connectionId: string,
@@ -71,7 +71,7 @@ export const useQueryTabs = ({
// failure as a toast. Returns null if the caller should bail out.
const acquireTabConnection = useCallback(async (): Promise<{
connectionId: string;
- backendPid: number | null;
+ nativeConnectionId: number | null;
} | null> => {
if (!guardLimit()) return null;
setIsOpeningTab(true);
@@ -101,7 +101,7 @@ export const useQueryTabs = ({
kind: "query",
id,
connectionId: conn.connectionId,
- backendPid: conn.backendPid,
+ nativeConnectionId: conn.nativeConnectionId,
isInTransaction: false,
lastFocusedAt: Date.now(),
title,
@@ -145,7 +145,7 @@ export const useQueryTabs = ({
kind: "browse",
id,
connectionId: conn.connectionId,
- backendPid: conn.backendPid,
+ nativeConnectionId: conn.nativeConnectionId,
isInTransaction: false,
lastFocusedAt: Date.now(),
title: `${schema}.${table}`,