@chatluna/patchbay 0.1.1 → 0.1.2

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chatluna/patchbay",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Cordis 4 patches for Koishi, Satori, Satori adapters and Cordis plugins, wired into yarn, pnpm or npm",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/patchbay.json CHANGED
@@ -3,7 +3,11 @@
3
3
  {
4
4
  "name": "@cordisjs/plugin-cli-cordis",
5
5
  "version": "1.0.5",
6
- "description": "Stable root include id, launcher include overrides and IPC health pings"
6
+ "description": "Stable root include id, launcher include overrides and IPC health pings; best-effort stdio, exit on parent disconnect and a bounded exit",
7
+ "fixes": [
8
+ "ChatLunaLab/v2-mirror#99",
9
+ "cordiverse/cordis#294"
10
+ ]
7
11
  },
8
12
  {
9
13
  "name": "@cordisjs/plugin-database",
@@ -14,12 +14,40 @@ index 4362cf8..ae92999 100644
14
14
  prelude?: EntryOptions[];
15
15
  }
16
16
  diff --git a/lib/worker/index.js b/lib/worker/index.js
17
- index 91ff829..ec55279 100644
17
+ index 91ff829..9c9b5ef 100644
18
18
  --- a/lib/worker/index.js
19
19
  +++ b/lib/worker/index.js
20
- @@ -31,6 +31,12 @@ function* apply(ctx, config = {}) {
20
+ @@ -17,20 +17,39 @@ __export(daemon_exports, {
21
+ });
22
+ var name = "daemon";
23
+ function* apply(ctx, config = {}) {
24
+ + // Bounded: a stuck `exit` listener must not keep a signalled or orphaned worker alive.
25
+ + function exit(signal) {
26
+ + setTimeout(() => process.exit(1), 1e4).unref();
27
+ + ctx.parallel("exit", signal).finally(() => process.exit());
28
+ + }
29
+ + __name(exit, "exit");
30
+ function handleSignal(signal) {
31
+ process.stderr.write("\x1B[2K\r");
32
+ if (config.autoRestart) {
33
+ process.send({ type: "exit" });
34
+ }
35
+ ctx.logger.info(`terminated by ${signal}`);
36
+ - ctx.parallel("exit", signal).finally(() => process.exit());
37
+ + exit(signal);
38
+ }
39
+ __name(handleSignal, "handleSignal");
40
+ process.on("SIGINT", handleSignal);
41
+ yield () => process.off("SIGINT", handleSignal);
21
42
  process.on("SIGTERM", handleSignal);
22
43
  yield () => process.off("SIGTERM", handleSignal);
44
+ + // The parent owns this worker: once its IPC channel closes, nothing pings, restarts or stops it.
45
+ + const onDisconnect = /* @__PURE__ */ __name(() => {
46
+ + ctx.logger.info("terminated by parent disconnect");
47
+ + exit("SIGTERM");
48
+ + }, "onDisconnect");
49
+ + process.on("disconnect", onDisconnect);
50
+ + yield () => process.off("disconnect", onDisconnect);
23
51
  process.send({ type: "start", body: config });
24
52
  + // Health over IPC: the supervisor pings, the worker answers; no network address involved.
25
53
  + const onMessage = /* @__PURE__ */ __name((message) => {
@@ -30,7 +58,20 @@ index 91ff829..ec55279 100644
30
58
  if (config.heartbeatInterval) {
31
59
  const timer = setInterval(() => {
32
60
  process.send({ type: "heartbeat" });
33
- @@ -59,12 +65,22 @@ async function start(config) {
61
+ @@ -43,6 +62,12 @@ __name(apply, "apply");
62
+ // src/worker/index.ts
63
+ async function start(config) {
64
+ const ctx = new Context();
65
+ + // Output is best-effort. Without a listener, a write to a closed stdout/stderr pipe becomes an
66
+ + // uncaughtException, which is logged to the same pipe and fails again, forever.
67
+ + const ignore = /* @__PURE__ */ __name(() => {
68
+ + }, "ignore");
69
+ + process.stdout.on("error", ignore);
70
+ + process.stderr.on("error", ignore);
71
+ process.on("uncaughtException", (error) => {
72
+ ctx.logger.error(error);
73
+ process.exitCode = 1;
74
+ @@ -59,12 +84,22 @@ async function start(config) {
34
75
  await ctx.loader.create(plugin);
35
76
  }
36
77
  await ctx.loader.create({