@antelopejs/dms 0.25.2 → 0.25.3

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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## v0.25.3
4
+
5
+ [compare changes](https://github.com/AntelopeJS/dms/compare/v0.25.2...v0.25.3)
6
+
7
+ ### 🩹 Fixes
8
+
9
+ - **dms:** Start a journey backend outside the ephemeral range, and fail its wait when it falls back ([#1308](https://github.com/AntelopeJS/dms/pull/1308))
10
+
11
+ ### ❤️ Contributors
12
+
13
+ - Antony Rizzitelli
14
+
3
15
  ## v0.25.2
4
16
 
5
17
  [compare changes](https://github.com/AntelopeJS/dms/compare/v0.25.1...v0.25.2)
@@ -47,7 +47,9 @@ export function ensureApi(state: import("./run-state.mjs").RunState): Promise<vo
47
47
  export function runBackendMode(state: RunState): BackendMode;
48
48
  /**
49
49
  * Starts a backend of the run on `database` and a free loopback port of its
50
- * own, from the run's build or `build`, without waiting for it, and records
50
+ * own outside the kernel's ephemeral range, where no other process's
51
+ * `listen(0)` or outgoing connection takes it, from the run's build or
52
+ * `build`, without waiting for it, and records
51
53
  * it in a file of its own. Its log is named after its database,
52
54
  * `backend_<suffix>.log`, so two backends that run at once write apart; the
53
55
  * first database's is `backend.log`.
@@ -6,18 +6,20 @@
6
6
  */
7
7
  export function probe(url: string): Promise<number | null>;
8
8
  /**
9
- * Polls `url` until it answers 200, the process exits or the timeout passes.
9
+ * Polls `url` until it answers 200, the process exits, `refused` tells why
10
+ * it never will, or the timeout passes.
10
11
  *
11
12
  * @param {string} url The readiness URL
12
13
  * @param {{ pid: number, log: string }} record The process that must serve it
13
14
  * @param {number} timeoutMs How long to wait
15
+ * @param {Refusal} [refused] Read at every poll
14
16
  * @returns {Promise<void>} Resolves once ready
15
- * @throws When the process exits first or the timeout passes, naming its log
17
+ * @throws When the process exits first, `refused` tells a reason or the timeout passes, naming its log
16
18
  */
17
19
  export function waitForOk(url: string, record: {
18
20
  pid: number;
19
21
  log: string;
20
- }, timeoutMs: number): Promise<void>;
22
+ }, timeoutMs: number, refused?: Refusal): Promise<void>;
21
23
  /**
22
24
  * Polls a loopback port until it accepts a connection, the process exits or
23
25
  * the timeout passes.
@@ -40,21 +42,22 @@ export function waitForPort(port: number, record: {
40
42
  * @param {number} port The port
41
43
  * @param {{ name: string, pid: number, log: string }} record The process that must listen
42
44
  * @param {number} timeoutMs How long to wait
45
+ * @param {Refusal} [refused] Read at every poll
43
46
  * @returns {Promise<void>} Resolves once the process listens
44
- * @throws When it exits first (the port was taken) or the timeout passes
47
+ * @throws When it exits first (the port was taken), `refused` tells a reason or the timeout passes
45
48
  */
46
49
  export function waitForOwnPort(port: number, record: {
47
50
  name: string;
48
51
  pid: number;
49
52
  log: string;
50
- }, timeoutMs: number): Promise<void>;
53
+ }, timeoutMs: number, refused?: Refusal): Promise<void>;
51
54
  /**
52
55
  * Waits until a backend listens on its own port and answers
53
56
  * `/api/onboarding/informations` there.
54
57
  *
55
58
  * @param {import("./run-state.mjs").ServerRecord} backend The backend
56
59
  * @returns {Promise<void>} Resolves once it answers 200
57
- * @throws When it exits first, another process holds its port or the timeout passes, naming its log
60
+ * @throws When it exits first, another process holds its port, its log says it listens on another port, or the timeout passes, naming its log
58
61
  */
59
62
  export function waitForBackend(backend: import("./run-state.mjs").ServerRecord): Promise<void>;
60
63
  /**
@@ -67,3 +70,7 @@ export function waitForBackend(backend: import("./run-state.mjs").ServerRecord):
67
70
  * @throws When it exits first, another process holds its port or the timeout passes, naming its log
68
71
  */
69
72
  export function waitForDashboard(state: Pick<import("./run-state.mjs").RunState, "webPort" | "webUrl">, frontend: import("./run-state.mjs").ProcessRecord): Promise<void>;
73
+ /**
74
+ * Why a wait cannot succeed any more, or `null` while it can
75
+ */
76
+ export type Refusal = () => string | null;
package/e2e/stack.mjs CHANGED
@@ -16,7 +16,6 @@ import { currentNamespaces, isSameProcess } from "./identity.mjs";
16
16
  import { reservedPorts } from "./reserved-ports.mjs";
17
17
  import { dropRunDatabases, startMongod } from "./mongo.mjs";
18
18
  import {
19
- freePort,
20
19
  restartablePort,
21
20
  runToEnd,
22
21
  startDetached,
@@ -265,7 +264,9 @@ const BACKEND_ARGS = {
265
264
 
266
265
  /**
267
266
  * Starts a backend of the run on `database` and a free loopback port of its
268
- * own, from the run's build or `build`, without waiting for it, and records
267
+ * own outside the kernel's ephemeral range, where no other process's
268
+ * `listen(0)` or outgoing connection takes it, from the run's build or
269
+ * `build`, without waiting for it, and records
269
270
  * it in a file of its own. Its log is named after its database,
270
271
  * `backend_<suffix>.log`, so two backends that run at once write apart; the
271
272
  * first database's is `backend.log`.
@@ -289,7 +290,7 @@ export async function launchBackend(
289
290
  mode = runBackendMode(state),
290
291
  ) {
291
292
  const { ajs } = cliPaths(build?.playground ?? state.playground);
292
- const port = await freePort(reservedPorts(state));
293
+ const port = await restartablePort(reservedPorts(state));
293
294
  const launch = spec(
294
295
  state,
295
296
  `backend${database.slice(state.databasePrefix.length)}`,
package/e2e/waits.mjs CHANGED
@@ -1,3 +1,4 @@
1
+ import { readFileSync } from "node:fs";
1
2
  import { createConnection } from "node:net";
2
3
  import { setTimeout as sleep } from "node:timers/promises";
3
4
  import { isAlive } from "./identity.mjs";
@@ -27,20 +28,31 @@ export async function probe(url) {
27
28
  }
28
29
 
29
30
  /**
30
- * Polls `url` until it answers 200, the process exits or the timeout passes.
31
+ * @typedef {() => string | null} Refusal Why a wait cannot succeed any more, or `null` while it can
32
+ */
33
+
34
+ /** @type {Refusal} */
35
+ const NEVER = () => null;
36
+
37
+ /**
38
+ * Polls `url` until it answers 200, the process exits, `refused` tells why
39
+ * it never will, or the timeout passes.
31
40
  *
32
41
  * @param {string} url The readiness URL
33
42
  * @param {{ pid: number, log: string }} record The process that must serve it
34
43
  * @param {number} timeoutMs How long to wait
44
+ * @param {Refusal} [refused] Read at every poll
35
45
  * @returns {Promise<void>} Resolves once ready
36
- * @throws When the process exits first or the timeout passes, naming its log
46
+ * @throws When the process exits first, `refused` tells a reason or the timeout passes, naming its log
37
47
  */
38
- export async function waitForOk(url, record, timeoutMs) {
48
+ export async function waitForOk(url, record, timeoutMs, refused = NEVER) {
39
49
  const deadline = Date.now() + timeoutMs;
40
50
  while (Date.now() < deadline) {
41
51
  if (!isAlive(record.pid)) {
42
52
  throw new Error(`${url}: the process exited first; see ${record.log}`);
43
53
  }
54
+ const reason = refused();
55
+ if (reason !== null) throw new Error(reason);
44
56
  if ((await probe(url)) === 200) return;
45
57
  await sleep(READY_POLL_MS);
46
58
  }
@@ -90,15 +102,18 @@ export async function waitForPort(port, record, timeoutMs) {
90
102
  * @param {number} port The port
91
103
  * @param {{ name: string, pid: number, log: string }} record The process that must listen
92
104
  * @param {number} timeoutMs How long to wait
105
+ * @param {Refusal} [refused] Read at every poll
93
106
  * @returns {Promise<void>} Resolves once the process listens
94
- * @throws When it exits first (the port was taken) or the timeout passes
107
+ * @throws When it exits first (the port was taken), `refused` tells a reason or the timeout passes
95
108
  */
96
- export async function waitForOwnPort(port, record, timeoutMs) {
109
+ export async function waitForOwnPort(port, record, timeoutMs, refused = NEVER) {
97
110
  if (listenersOf(port) === null) return waitForPort(port, record, timeoutMs);
98
111
  const deadline = Date.now() + timeoutMs;
99
112
  while (Date.now() < deadline && isAlive(record.pid)) {
100
113
  const own = new Set([record.pid, ...descendantsOf([record.pid])]);
101
114
  if (listenersOf(port)?.some((pid) => own.has(pid))) return;
115
+ const reason = refused();
116
+ if (reason !== null) throw new Error(reason);
102
117
  await sleep(READY_POLL_MS);
103
118
  }
104
119
  throw new Error(
@@ -106,20 +121,43 @@ export async function waitForOwnPort(port, record, timeoutMs) {
106
121
  );
107
122
  }
108
123
 
124
+ /**
125
+ * Why a backend never listens on its port: its log says the port was in use
126
+ * when it started, and it listens on another one instead.
127
+ *
128
+ * @param {import("./run-state.mjs").ServerRecord} backend The backend
129
+ * @returns {Refusal}
130
+ */
131
+ function movedOff(backend) {
132
+ const line = `Port ${backend.port} in use, listening on `;
133
+ return () => {
134
+ let log = "";
135
+ try {
136
+ log = readFileSync(backend.log, "utf8");
137
+ } catch {
138
+ return null;
139
+ }
140
+ if (!log.includes(line)) return null;
141
+ return `${backend.name} found port ${backend.port} in use when it started and listens on another one; see ${backend.log}`;
142
+ };
143
+ }
144
+
109
145
  /**
110
146
  * Waits until a backend listens on its own port and answers
111
147
  * `/api/onboarding/informations` there.
112
148
  *
113
149
  * @param {import("./run-state.mjs").ServerRecord} backend The backend
114
150
  * @returns {Promise<void>} Resolves once it answers 200
115
- * @throws When it exits first, another process holds its port or the timeout passes, naming its log
151
+ * @throws When it exits first, another process holds its port, its log says it listens on another port, or the timeout passes, naming its log
116
152
  */
117
153
  export async function waitForBackend(backend) {
118
- await waitForOwnPort(backend.port, backend, READY_TIMEOUT_MS);
154
+ const refused = movedOff(backend);
155
+ await waitForOwnPort(backend.port, backend, READY_TIMEOUT_MS, refused);
119
156
  await waitForOk(
120
157
  `http://127.0.0.1:${backend.port}/api/onboarding/informations`,
121
158
  backend,
122
159
  READY_TIMEOUT_MS,
160
+ refused,
123
161
  );
124
162
  }
125
163
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antelopejs/dms",
3
- "version": "0.25.2",
3
+ "version": "0.25.3",
4
4
  "description": "AntelopeJS DMS. Plug in your PostgreSQL, MySQL, MariaDB, MongoDB or RethinkDB database and your coding agent builds a back office and analytics dashboard as typed TypeScript. Real-time updates on the data the DMS manages.",
5
5
  "keywords": [
6
6
  "antelopejs",
@@ -211,7 +211,7 @@
211
211
  "optional": true
212
212
  }
213
213
  },
214
- "gitHead": "120b32596b6e0a703e8b7297fbc4be04ace4a0da",
214
+ "gitHead": "b6ffce4fbccdbc5a77f1a0b3cab420abcaea0926",
215
215
  "scripts": {
216
216
  "build": "pnpm --filter @antelopejs/interface-dms --filter @antelopejs/interface-dms-builder build && rimraf dist && antelopejs-tsc && tsc-alias && tsc -p e2e/tsconfig.types.json",
217
217
  "dev": "ajs project run --inspect -w -p playground",