Skip to content

Commit 327ddd6

Browse files
Merge pull request #4328 from opral/4327
Remove shutdown wait on fileQueueSettled and silence known shutdown noise in CLI
2 parents 4b2e7ee + b8d0b20 commit 327ddd6

6 files changed

Lines changed: 42 additions & 22 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@inlang/cli": patch
3+
---
4+
5+
Fix CLI commands not terminating by removing the shutdown wait on `fileQueueSettled`.
6+
7+
Also silence known non-actionable shutdown noise from background file queue processing when the DB is already closed.

packages/cli/src/commands/machine/translate.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
/* eslint-disable @typescript-eslint/no-non-null-assertion */
22
import { Command } from "commander";
33
import { rpc } from "@inlang/rpc";
4-
import {
5-
getInlangProject,
6-
settleLastUsedProjectFileQueue,
7-
} from "../../utilities/getInlangProject.js";
4+
import { getInlangProject } from "../../utilities/getInlangProject.js";
85
import { log, logError } from "../../utilities/log.js";
96
import {
107
saveProjectToDirectory,
@@ -41,7 +38,6 @@ export const translate = new Command()
4138
logError(error);
4239
exitCode = 1;
4340
} finally {
44-
await settleLastUsedProjectFileQueue();
4541
process.exit(exitCode);
4642
}
4743
});

packages/cli/src/commands/validate/index.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import { Command } from "commander";
2-
import {
3-
getInlangProject,
4-
settleLastUsedProjectFileQueue,
5-
} from "../../utilities/getInlangProject.js";
2+
import { getInlangProject } from "../../utilities/getInlangProject.js";
63
import { log } from "../../utilities/log.js";
74
import { projectOption } from "../../utilities/globalFlags.js";
85

@@ -32,7 +29,6 @@ export async function validateCommandAction(args: { project: string }) {
3229
log.error(error);
3330
exitCode = 1;
3431
} finally {
35-
await settleLastUsedProjectFileQueue();
3632
process.exit(exitCode);
3733
}
3834
}

packages/cli/src/main.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { machine } from "./commands/machine/index.js";
33
import { plugin } from "./commands/plugin/index.js";
44
import { version } from "../package.json";
55
import { initErrorMonitoring } from "./services/error-monitoring/implementation.js";
6+
import { silenceKnownShutdownNoise } from "./services/error-monitoring/silenceKnownShutdownNoise.js";
67
import { validate } from "./commands/validate/index.js";
78
import { capture } from "./telemetry/capture.js";
89
import { lastUsedProject } from "./utilities/getInlangProject.js";
@@ -11,6 +12,7 @@ import { lint } from "./commands/lint/index.js";
1112
// --------------- INIT ---------------
1213

1314
initErrorMonitoring();
15+
silenceKnownShutdownNoise();
1416
// checks whether the gitOrigin corresponds to the pattern
1517

1618
// beautiful logging
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
const FILE_QUEUE_CONTEXT_PATTERN = /(file queue|Error processing file queue entry)/i;
2+
const DB_CLOSED_PATTERN = /(DB has been closed|driver has already been destroyed)/i;
3+
4+
function shouldSilenceConsoleError(args: unknown[]): boolean {
5+
if (args.length === 0) {
6+
return false;
7+
}
8+
9+
const text = args
10+
.map((arg) => {
11+
if (arg instanceof Error) {
12+
return `${arg.name}: ${arg.message}`;
13+
}
14+
return String(arg);
15+
})
16+
.join(" ");
17+
18+
return FILE_QUEUE_CONTEXT_PATTERN.test(text) && DB_CLOSED_PATTERN.test(text);
19+
}
20+
21+
export function silenceKnownShutdownNoise(): void {
22+
const originalConsoleError = console.error.bind(console);
23+
24+
console.error = (...args: unknown[]) => {
25+
if (shouldSilenceConsoleError(args)) {
26+
return;
27+
}
28+
29+
originalConsoleError(...args);
30+
};
31+
}

packages/cli/src/utilities/getInlangProject.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import fs from "node:fs";
22
import { loadProjectFromDirectory, type InlangProject } from "@inlang/sdk";
3-
import { fileQueueSettled } from "@inlang/sdk/lix";
43
import { resolve } from "node:path";
54

65
/**
@@ -31,14 +30,3 @@ export async function getInlangProject(args: {
3130
process.exit(1);
3231
}
3332
}
34-
35-
export async function settleLastUsedProjectFileQueue(): Promise<void> {
36-
if (!lastUsedProject) {
37-
return;
38-
}
39-
try {
40-
await fileQueueSettled({ lix: lastUsedProject.lix });
41-
} catch {
42-
// Best-effort: ignore queue settle failures during shutdown.
43-
}
44-
}

0 commit comments

Comments
 (0)