Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions ui/desktop/src/goosed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ export interface GoosedResult {
workingDir: string;
process: ChildProcess | null;
errorLog: string[];
stopErrorLogCollection: () => void;
cleanup: () => Promise<void>;
client: Client;
certFingerprint: string | null;
Expand Down Expand Up @@ -199,6 +200,7 @@ export const startGoosed = async (options: StartGoosedOptions): Promise<GoosedRe
workingDir,
process: null,
errorLog,
stopErrorLogCollection: () => {},
cleanup: async () => {
logger.info('Not killing external process that is managed externally');
},
Expand All @@ -217,6 +219,7 @@ export const startGoosed = async (options: StartGoosedOptions): Promise<GoosedRe
workingDir,
process: null,
errorLog,
stopErrorLogCollection: () => {},
cleanup: async () => {
logger.info('Not killing external process that is managed externally');
},
Expand Down Expand Up @@ -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');
for (const line of lines) {
if (line.trim()) {
errorLog.push(line);
if (isFatalError(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) => {
logger.info(`goosed process exited with code ${code} for port ${port} and dir ${workingDir}`);
Expand Down Expand Up @@ -363,6 +369,7 @@ export const startGoosed = async (options: StartGoosedOptions): Promise<GoosedRe
workingDir,
process: goosedProcess,
errorLog,
stopErrorLogCollection,
cleanup,
client: goosedClientForUrlAndSecret(baseUrl, serverSecret),
certFingerprint,
Expand Down
13 changes: 12 additions & 1 deletion ui/desktop/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,13 @@ const createChat = async (app: App, options: CreateChatOptions = {}) => {
await goosedResult.cleanup();
});

const { baseUrl, workingDir, process: goosedProcess, errorLog } = goosedResult;
const {
baseUrl,
workingDir,
process: goosedProcess,
errorLog,
stopErrorLogCollection,
} = goosedResult;

const mainWindowState = windowStateKeeper({
defaultWidth: 940,
Expand Down Expand Up @@ -698,6 +704,11 @@ const createChat = async (app: App, options: CreateChatOptions = {}) => {
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
mainWindowState.manage(mainWindow);

Expand Down
Loading