Stop collecting goosed stderr after startup (#7814)
Co-authored-by: Douwe Osinga <douwe@squareup.com>
This commit is contained in:
@@ -159,6 +159,7 @@ export interface GoosedResult {
|
|||||||
workingDir: string;
|
workingDir: string;
|
||||||
process: ChildProcess | null;
|
process: ChildProcess | null;
|
||||||
errorLog: string[];
|
errorLog: string[];
|
||||||
|
stopErrorLogCollection: () => void;
|
||||||
cleanup: () => Promise<void>;
|
cleanup: () => Promise<void>;
|
||||||
client: Client;
|
client: Client;
|
||||||
certFingerprint: string | null;
|
certFingerprint: string | null;
|
||||||
@@ -199,6 +200,7 @@ export const startGoosed = async (options: StartGoosedOptions): Promise<GoosedRe
|
|||||||
workingDir,
|
workingDir,
|
||||||
process: null,
|
process: null,
|
||||||
errorLog,
|
errorLog,
|
||||||
|
stopErrorLogCollection: () => {},
|
||||||
cleanup: async () => {
|
cleanup: async () => {
|
||||||
logger.info('Not killing external process that is managed externally');
|
logger.info('Not killing external process that is managed externally');
|
||||||
},
|
},
|
||||||
@@ -217,6 +219,7 @@ export const startGoosed = async (options: StartGoosedOptions): Promise<GoosedRe
|
|||||||
workingDir,
|
workingDir,
|
||||||
process: null,
|
process: null,
|
||||||
errorLog,
|
errorLog,
|
||||||
|
stopErrorLogCollection: () => {},
|
||||||
cleanup: async () => {
|
cleanup: async () => {
|
||||||
logger.info('Not killing external process that is managed externally');
|
logger.info('Not killing external process that is managed externally');
|
||||||
},
|
},
|
||||||
@@ -300,19 +303,22 @@ export const startGoosed = async (options: StartGoosedOptions): Promise<GoosedRe
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
goosedProcess.stderr?.on('data', (data: Buffer) => {
|
const onStderrData = (data: Buffer) => {
|
||||||
const lines = data.toString().split('\n');
|
const lines = data.toString().split('\n');
|
||||||
for (const line of lines) {
|
for (const line of lines) {
|
||||||
if (line.trim()) {
|
if (line.trim()) {
|
||||||
errorLog.push(line);
|
errorLog.push(line);
|
||||||
if (isFatalError(line)) {
|
if (isFatalError(line)) {
|
||||||
logger.error(`goosed stderr for port ${port} and dir ${workingDir}: ${line}`);
|
logger.error(`goosed stderr for port ${port} and dir ${workingDir}: ${line}`);
|
||||||
} else {
|
|
||||||
logger.info(`goosed stderr for port ${port} and dir ${workingDir}: ${line}`);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
goosedProcess.stderr?.on('data', onStderrData);
|
||||||
|
|
||||||
|
const stopErrorLogCollection = () => {
|
||||||
|
goosedProcess.stderr?.off('data', onStderrData);
|
||||||
|
};
|
||||||
|
|
||||||
goosedProcess.on('exit', (code) => {
|
goosedProcess.on('exit', (code) => {
|
||||||
logger.info(`goosed process exited with code ${code} for port ${port} and dir ${workingDir}`);
|
logger.info(`goosed process exited with code ${code} for port ${port} and dir ${workingDir}`);
|
||||||
@@ -363,6 +369,7 @@ export const startGoosed = async (options: StartGoosedOptions): Promise<GoosedRe
|
|||||||
workingDir,
|
workingDir,
|
||||||
process: goosedProcess,
|
process: goosedProcess,
|
||||||
errorLog,
|
errorLog,
|
||||||
|
stopErrorLogCollection,
|
||||||
cleanup,
|
cleanup,
|
||||||
client: goosedClientForUrlAndSecret(baseUrl, serverSecret),
|
client: goosedClientForUrlAndSecret(baseUrl, serverSecret),
|
||||||
certFingerprint,
|
certFingerprint,
|
||||||
|
|||||||
+12
-1
@@ -594,7 +594,13 @@ const createChat = async (app: App, options: CreateChatOptions = {}) => {
|
|||||||
await goosedResult.cleanup();
|
await goosedResult.cleanup();
|
||||||
});
|
});
|
||||||
|
|
||||||
const { baseUrl, workingDir, process: goosedProcess, errorLog } = goosedResult;
|
const {
|
||||||
|
baseUrl,
|
||||||
|
workingDir,
|
||||||
|
process: goosedProcess,
|
||||||
|
errorLog,
|
||||||
|
stopErrorLogCollection,
|
||||||
|
} = goosedResult;
|
||||||
|
|
||||||
const mainWindowState = windowStateKeeper({
|
const mainWindowState = windowStateKeeper({
|
||||||
defaultWidth: 940,
|
defaultWidth: 940,
|
||||||
@@ -698,6 +704,11 @@ const createChat = async (app: App, options: CreateChatOptions = {}) => {
|
|||||||
app.quit();
|
app.quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// errorLog is only needed during startup to detect fatal errors.
|
||||||
|
// Stop collecting stderr to avoid unbounded memory growth over long sessions.
|
||||||
|
stopErrorLogCollection();
|
||||||
|
errorLog.length = 0;
|
||||||
|
|
||||||
// Let windowStateKeeper manage the window
|
// Let windowStateKeeper manage the window
|
||||||
mainWindowState.manage(mainWindow);
|
mainWindowState.manage(mainWindow);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user