fix(mysql): harden process list refresh and kill handling
This commit is contained in:
1 parent
c19f3e201b
commit
446e995063
3 files changed
+74
-4
No files matched your search
@@ -26,6 +26,11 @@ export const MIN_REFRESH_SECONDS = 1;
|
||||
export const MAX_REFRESH_SECONDS = 3600;
|
||||
export const DEFAULT_REFRESH_SECONDS = 5;
|
||||
|
||||
export interface ProcessListLoadCoordinator {
|
||||
tryStart(): boolean;
|
||||
finish(): void;
|
||||
}
|
||||
|
||||
export interface ProcessRow {
|
||||
id: number;
|
||||
user: string;
|
||||
@@ -37,6 +42,37 @@ export interface ProcessRow {
|
||||
info: string | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Keep manual and timer-driven refreshes on the same single-flight guard. Slow
|
||||
* servers must not accumulate process-list queries faster than they complete.
|
||||
*/
|
||||
export function createProcessListLoadCoordinator(): ProcessListLoadCoordinator {
|
||||
let inFlight = false;
|
||||
return {
|
||||
tryStart() {
|
||||
if (inFlight) return false;
|
||||
inFlight = true;
|
||||
return true;
|
||||
},
|
||||
finish() {
|
||||
inFlight = false;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/** Return the server-provided message for the first failed batch statement. */
|
||||
export function processListExecutionError(results: QueryResult[]): string | null {
|
||||
const failed = results.find((result) => result.execution_error === true);
|
||||
if (!failed) return null;
|
||||
const message = failed.rows?.[0]?.[0];
|
||||
return message === null || message === undefined || String(message).length === 0 ? "Query execution failed" : String(message);
|
||||
}
|
||||
|
||||
/** A truncated result only establishes a lower bound for the session count. */
|
||||
export function processListSessionCount(count: number, truncated: boolean): number | string {
|
||||
return truncated ? `${count}+` : count;
|
||||
}
|
||||
|
||||
function columnIndex(columns: string[], name: string): number {
|
||||
const target = name.toLowerCase();
|
||||
return columns.findIndex((column) => column.toLowerCase() === target);
|
||||
|
||||
Reference in new issue
Block a user