@hile/cli 2.0.8 → 2.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,7 @@
1
1
  /**
2
- * 注册进程退出钩子:进程退出时先执行 container.shutdown(),**仅在其完成后**才执行 offEvent 并 exit。
3
- * shutdown() 未完成,进程会挂起,不会被关闭(受 FORCE_EXIT_AFTER_MS 上限保护)。
2
+ * 注册进程退出钩子。
3
+ * 进程退出时先执行 container.shutdown(),完成后调用 exit() 调度 process.exit()。
4
+ * 若 process.exit() 被 pino/thread-stream 的 Atomics.wait() 阻塞,1s 后 process.abort() 兜底。
4
5
  */
5
6
  export declare function registerExitHook(offEvent: () => void): void;
6
7
  export declare function useExit(fn: () => void | Promise<void>): Promise<void>;
package/dist/exitHook.js CHANGED
@@ -1,10 +1,11 @@
1
1
  import exitHook from 'async-exit-hook';
2
2
  import { container } from '@hile/core';
3
- /** 强制退出超时:仅当 shutdown 未在该时间内完成时才强制退出,默认约 24 天,等效于「等 shutdown 完成再退出」 */
4
- const FORCE_EXIT_AFTER_MS = 2 ** 31 - 1;
3
+ /** shutdown 未在该时间内完成时强制退出 */
4
+ const FORCE_EXIT_AFTER_MS = 10_000;
5
5
  /**
6
- * 注册进程退出钩子:进程退出时先执行 container.shutdown(),**仅在其完成后**才执行 offEvent 并 exit。
7
- * shutdown() 未完成,进程会挂起,不会被关闭(受 FORCE_EXIT_AFTER_MS 上限保护)。
6
+ * 注册进程退出钩子。
7
+ * 进程退出时先执行 container.shutdown(),完成后调用 exit() 调度 process.exit()。
8
+ * 若 process.exit() 被 pino/thread-stream 的 Atomics.wait() 阻塞,1s 后 process.abort() 兜底。
8
9
  */
9
10
  export function registerExitHook(offEvent) {
10
11
  const hook = exitHook;
@@ -14,17 +15,9 @@ export function registerExitHook(offEvent) {
14
15
  exitHook(async (exit) => {
15
16
  try {
16
17
  await container.shutdown();
17
- await new Promise((resolve, reject) => {
18
- try {
19
- if (process.stdin.isTTY) {
20
- process.stdin.unref();
21
- }
22
- resolve();
23
- }
24
- catch (e) {
25
- reject(e);
26
- }
27
- });
18
+ if (process.stdin.isTTY) {
19
+ process.stdin.unref();
20
+ }
28
21
  }
29
22
  catch (e) {
30
23
  console.error(e);
@@ -32,6 +25,10 @@ export function registerExitHook(offEvent) {
32
25
  finally {
33
26
  offEvent();
34
27
  exit();
28
+ // process.exit() can hang due to pino/thread-stream exit handlers
29
+ // that use Atomics.wait() to block on worker threads.
30
+ // If we're still running after 1s, force kill.
31
+ setTimeout(() => process.abort(), 1000).unref();
35
32
  }
36
33
  });
37
34
  }
@@ -39,23 +36,16 @@ export async function useExit(fn) {
39
36
  exitHook(async (exit) => {
40
37
  try {
41
38
  await Promise.resolve(fn());
42
- await new Promise((resolve, reject) => {
43
- try {
44
- if (process.stdin.isTTY) {
45
- process.stdin.unref();
46
- }
47
- resolve();
48
- }
49
- catch (e) {
50
- reject(e);
51
- }
52
- });
39
+ if (process.stdin.isTTY) {
40
+ process.stdin.unref();
41
+ }
53
42
  }
54
43
  catch (e) {
55
44
  console.error(e);
56
45
  }
57
46
  finally {
58
47
  exit();
48
+ setTimeout(() => process.abort(), 1000).unref();
59
49
  }
60
50
  });
61
51
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hile/cli",
3
- "version": "2.0.8",
3
+ "version": "2.0.9",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "scripts": {
@@ -29,8 +29,8 @@
29
29
  },
30
30
  "dependencies": {
31
31
  "@hile/core": "^2.0.1",
32
- "@hile/logger": "^2.0.1",
33
- "@hile/micro": "^2.0.5",
32
+ "@hile/logger": "^2.0.2",
33
+ "@hile/micro": "^2.0.6",
34
34
  "async-exit-hook": "^2.0.1",
35
35
  "commander": "^14.0.3",
36
36
  "glob": "^13.0.6",
@@ -38,5 +38,5 @@
38
38
  "tsx": "^4.21.0",
39
39
  "yaml": "^2.9.0"
40
40
  },
41
- "gitHead": "ee65892b77e87ff14470dee72a3ff45b6c467311"
41
+ "gitHead": "cf0c977950926cce605271a45a6c970506f6ed97"
42
42
  }