@hadoku/game-server 0.1.232 → 0.1.233
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/dist/play/local-jvm.d.ts +20 -54
- package/dist/play/local-jvm.js +32 -49
- package/package.json +5 -5
package/dist/play/local-jvm.d.ts
CHANGED
|
@@ -68,9 +68,8 @@
|
|
|
68
68
|
* (`AiFlatMc`); default `AI_FLAT_MC`. Read per match, so a restart of the
|
|
69
69
|
* server flips it for every match started after, on JVMs already running too
|
|
70
70
|
*
|
|
71
|
-
* The bridge needs a JDK
|
|
72
|
-
*
|
|
73
|
-
* (on the production host that is a JRE with no `javac`).
|
|
71
|
+
* The bridge needs a JDK: `bridgeLaunch` compiles it with the `javac` beside `java`, and refuses a
|
|
72
|
+
* `java` with none (a JRE).
|
|
74
73
|
*/
|
|
75
74
|
import { type EngineRuntime, type SweepResult } from './engine-runtime.js';
|
|
76
75
|
import type { JvmLauncher } from './jvm-transport.js';
|
|
@@ -183,67 +182,34 @@ export declare function jvmHostConfig(bridgeSource: string, env?: NodeJS.Process
|
|
|
183
182
|
*/
|
|
184
183
|
export declare const BRIDGE_CACHE_MAX_AGE_MS: number;
|
|
185
184
|
/**
|
|
186
|
-
* What a bridge JVM is launched with after its flags: `-cp <
|
|
185
|
+
* What a bridge JVM is launched with after its flags: `-cp <classes>:<jar> <main>`.
|
|
187
186
|
*
|
|
188
|
-
*
|
|
189
|
-
*
|
|
190
|
-
*
|
|
191
|
-
*
|
|
192
|
-
* compiled once instead, by the `javac` beside `config.java`, into a directory
|
|
193
|
-
* named for a hash of everything that decides the result: the source's bytes,
|
|
194
|
-
* the jar it is compiled against, and the JDK. An edited bridge is therefore a
|
|
195
|
-
* different directory, never a stale one, and it still takes effect at the next
|
|
196
|
-
* JVM with no restart, as it did under the source launcher. `-proc:none` is what
|
|
197
|
-
* that launcher does too.
|
|
187
|
+
* The bridge is compiled once, by the `javac` beside `config.java`, into a directory named for
|
|
188
|
+
* `bridgeVersion`: an edited bridge is a different directory, never a stale one, and it takes
|
|
189
|
+
* effect at the next JVM with no restart. `-sourcepath <the bridge's directory>` lets `javac` find
|
|
190
|
+
* every class the main reads in the files beside it (`PoolService` calls `PlayBridge.forgeCardName`).
|
|
198
191
|
*
|
|
199
|
-
* Two processes may compile the same version at once (a deploy beside a CI job):
|
|
200
|
-
*
|
|
201
|
-
*
|
|
202
|
-
*
|
|
203
|
-
*
|
|
204
|
-
* (`PlayBridge`, `PoolService`) can share a version: each still gets its own
|
|
205
|
-
* directory, so a reader finding ITS main's class already there is never
|
|
206
|
-
* looking at one another process is still mid-write on for a DIFFERENT main.
|
|
192
|
+
* Two processes may compile the same version at once (a deploy beside a CI job): each compiles
|
|
193
|
+
* into its own temporary directory and RENAMES it into place, so a JVM never sees half a
|
|
194
|
+
* directory, and the loser's copy is deleted. The directory carries the main's own name as well as
|
|
195
|
+
* the version, because two mains (`PlayBridge`, `PoolService`) share a version: a reader that
|
|
196
|
+
* finds ITS main's class there is never looking at a directory another process is still writing.
|
|
207
197
|
*
|
|
208
|
-
* With no `javac` there (a
|
|
209
|
-
*
|
|
210
|
-
* `jvm-spawned` line says which one that JVM got.
|
|
211
|
-
*
|
|
212
|
-
* `-sourcepath <bridgeSource's own directory>` is on every `javac` invocation
|
|
213
|
-
* (wave 73 §D): `PlayBridge.java` and `PoolService.java` sit beside each other
|
|
214
|
-
* there, and `PoolService.java` calls `PlayBridge.forgeCardName` — a
|
|
215
|
-
* package-private static method, reachable because both are top-level classes
|
|
216
|
-
* in the same (unnamed) package — so compiling `PoolService.java` alone needs
|
|
217
|
-
* `javac` to find and compile `PlayBridge.java` too. It is a no-op for
|
|
218
|
-
* `PlayBridge.java`'s own compile: nothing in that file references a sibling
|
|
219
|
-
* class `javac` cannot already resolve from the jar, so `-sourcepath` is never
|
|
220
|
-
* consulted for it, and the compiled output is unchanged.
|
|
198
|
+
* With no `javac` there (a JRE), or a compile that fails, it logs `bridge-compile-failed` with
|
|
199
|
+
* javac's own words and throws: a bridge that does not compile can start nothing.
|
|
221
200
|
*/
|
|
222
201
|
/** What compiling and launching a bridge reads from a host's configuration. */
|
|
223
202
|
export type BridgeConfig = Pick<JvmHostConfig, 'java' | 'jar' | 'bridgeSource' | 'bridgeCache'>;
|
|
224
203
|
export declare function bridgeLaunch(config: BridgeConfig, log: (entry: Record<string, unknown>) => void): {
|
|
225
204
|
args: string[];
|
|
226
|
-
how: 'compiled' | 'source';
|
|
227
205
|
};
|
|
206
|
+
/** Every `.java` beside `bridgeSource`, sorted: the files one compile of it can read, so what "the bridge" is. */
|
|
207
|
+
export declare function bridgeSources(bridgeSource: string): string[];
|
|
228
208
|
/**
|
|
229
|
-
*
|
|
230
|
-
*
|
|
231
|
-
*
|
|
232
|
-
*
|
|
233
|
-
* deterministic digest — otherwise an edit to a file that IS referenced,
|
|
234
|
-
* with the referencing file itself unchanged, would keep the old key and so
|
|
235
|
-
* silently serve a stale compiled class for it.
|
|
236
|
-
*
|
|
237
|
-
* Covering the whole directory means `PlayBridge.java`'s own key also changes
|
|
238
|
-
* when `PoolService.java` changes, and vice versa, even on an edit that
|
|
239
|
-
* changes nothing either file's compile actually depends on. Accepted for
|
|
240
|
-
* simplicity: the alternative is having `javac` report exactly which
|
|
241
|
-
* siblings it resolved for THAT compile (it does not expose this), and
|
|
242
|
-
* tracking it per bridge source — real staleness is worse than an occasional
|
|
243
|
-
* needless recompile.
|
|
244
|
-
*
|
|
245
|
-
* Exported so the key itself is unit-testable (`host.test.ts`, "an edited
|
|
246
|
-
* SIBLING .java changes the key too") without a real compile.
|
|
209
|
+
* The compiled bridge's cache key: every `bridgeSources` file (`-sourcepath` can pull any of them
|
|
210
|
+
* into the compile), the jar it is compiled against, and the JDK. So `PlayBridge` recompiles when
|
|
211
|
+
* only `PoolService.java` changed, and the other way round: `javac` does not say which siblings
|
|
212
|
+
* one compile read, and a stale class is worse than a needless compile.
|
|
247
213
|
*/
|
|
248
214
|
export declare function bridgeVersion(config: BridgeConfig): string;
|
|
249
215
|
/** `{hostId, pid, startedAt}`: what a later process finds a running JVM by. Written at launch. */
|
package/dist/play/local-jvm.js
CHANGED
|
@@ -68,9 +68,8 @@
|
|
|
68
68
|
* (`AiFlatMc`); default `AI_FLAT_MC`. Read per match, so a restart of the
|
|
69
69
|
* server flips it for every match started after, on JVMs already running too
|
|
70
70
|
*
|
|
71
|
-
* The bridge needs a JDK
|
|
72
|
-
*
|
|
73
|
-
* (on the production host that is a JRE with no `javac`).
|
|
71
|
+
* The bridge needs a JDK: `bridgeLaunch` compiles it with the `javac` beside `java`, and refuses a
|
|
72
|
+
* `java` with none (a JRE).
|
|
74
73
|
*/
|
|
75
74
|
import { spawn, spawnSync } from 'node:child_process';
|
|
76
75
|
import { createHash, randomBytes } from 'node:crypto';
|
|
@@ -190,27 +189,22 @@ export function jvmHostConfig(bridgeSource, env = process.env) {
|
|
|
190
189
|
*/
|
|
191
190
|
export const BRIDGE_CACHE_MAX_AGE_MS = 14 * 24 * 60 * 60 * 1000;
|
|
192
191
|
export function bridgeLaunch(config, log) {
|
|
193
|
-
const
|
|
192
|
+
const refused = (error) => {
|
|
193
|
+
log({ evt: 'bridge-compile-failed', error });
|
|
194
|
+
return new Error(`the bridge does not compile: ${error}`);
|
|
195
|
+
};
|
|
194
196
|
const javac = join(dirname(config.java), 'javac');
|
|
195
197
|
if (!existsSync(javac))
|
|
196
|
-
|
|
198
|
+
throw refused(`no javac beside ${config.java}`);
|
|
197
199
|
const main = basename(config.bridgeSource, '.java');
|
|
198
200
|
let dir;
|
|
199
201
|
try {
|
|
200
|
-
// The main's own name is part of the directory, not just the version: two
|
|
201
|
-
// mains compiling the same siblings (PlayBridge.java and PoolService.java,
|
|
202
|
-
// most of the time) must never share one, or a reader that finds ITS
|
|
203
|
-
// main's class already there could be looking at a directory ANOTHER
|
|
204
|
-
// process is still mid-write on the OTHER main's classes. One main, one
|
|
205
|
-
// directory, keeps the rename below the only thing that makes a directory
|
|
206
|
-
// visible at all — no reader ever sees a half-written one.
|
|
207
202
|
dir = join(config.bridgeCache, `${main}-${bridgeVersion(config)}`);
|
|
208
203
|
}
|
|
209
204
|
catch (err) {
|
|
210
|
-
|
|
211
|
-
return source;
|
|
205
|
+
throw refused(err.message);
|
|
212
206
|
}
|
|
213
|
-
const compiled = { args: ['-cp', `${dir}:${config.jar}`, main]
|
|
207
|
+
const compiled = { args: ['-cp', `${dir}:${config.jar}`, main] };
|
|
214
208
|
if (existsSync(join(dir, `${main}.class`))) {
|
|
215
209
|
try {
|
|
216
210
|
// Launched now, so not stale: the pruning below goes by this.
|
|
@@ -241,8 +235,7 @@ export function bridgeLaunch(config, log) {
|
|
|
241
235
|
log({ evt: 'bridge-compiled', dir, ms: Date.now() - started });
|
|
242
236
|
}
|
|
243
237
|
catch (err) {
|
|
244
|
-
|
|
245
|
-
return source;
|
|
238
|
+
throw refused(err.message);
|
|
246
239
|
}
|
|
247
240
|
finally {
|
|
248
241
|
rmSync(staging, { recursive: true, force: true });
|
|
@@ -260,34 +253,24 @@ export function bridgeLaunch(config, log) {
|
|
|
260
253
|
}
|
|
261
254
|
return compiled;
|
|
262
255
|
}
|
|
256
|
+
/** Every `.java` beside `bridgeSource`, sorted: the files one compile of it can read, so what "the bridge" is. */
|
|
257
|
+
export function bridgeSources(bridgeSource) {
|
|
258
|
+
const dir = dirname(bridgeSource);
|
|
259
|
+
return readdirSync(dir)
|
|
260
|
+
.filter((f) => f.endsWith('.java'))
|
|
261
|
+
.sort()
|
|
262
|
+
.map((f) => join(dir, f));
|
|
263
|
+
}
|
|
263
264
|
/**
|
|
264
|
-
*
|
|
265
|
-
*
|
|
266
|
-
*
|
|
267
|
-
*
|
|
268
|
-
* deterministic digest — otherwise an edit to a file that IS referenced,
|
|
269
|
-
* with the referencing file itself unchanged, would keep the old key and so
|
|
270
|
-
* silently serve a stale compiled class for it.
|
|
271
|
-
*
|
|
272
|
-
* Covering the whole directory means `PlayBridge.java`'s own key also changes
|
|
273
|
-
* when `PoolService.java` changes, and vice versa, even on an edit that
|
|
274
|
-
* changes nothing either file's compile actually depends on. Accepted for
|
|
275
|
-
* simplicity: the alternative is having `javac` report exactly which
|
|
276
|
-
* siblings it resolved for THAT compile (it does not expose this), and
|
|
277
|
-
* tracking it per bridge source — real staleness is worse than an occasional
|
|
278
|
-
* needless recompile.
|
|
279
|
-
*
|
|
280
|
-
* Exported so the key itself is unit-testable (`host.test.ts`, "an edited
|
|
281
|
-
* SIBLING .java changes the key too") without a real compile.
|
|
265
|
+
* The compiled bridge's cache key: every `bridgeSources` file (`-sourcepath` can pull any of them
|
|
266
|
+
* into the compile), the jar it is compiled against, and the JDK. So `PlayBridge` recompiles when
|
|
267
|
+
* only `PoolService.java` changed, and the other way round: `javac` does not say which siblings
|
|
268
|
+
* one compile read, and a stale class is worse than a needless compile.
|
|
282
269
|
*/
|
|
283
270
|
export function bridgeVersion(config) {
|
|
284
|
-
const dir = dirname(config.bridgeSource);
|
|
285
|
-
const siblings = readdirSync(dir)
|
|
286
|
-
.filter((f) => f.endsWith('.java'))
|
|
287
|
-
.sort();
|
|
288
271
|
const hash = createHash('sha256');
|
|
289
|
-
for (const file of
|
|
290
|
-
hash.update(readFileSync(
|
|
272
|
+
for (const file of bridgeSources(config.bridgeSource))
|
|
273
|
+
hash.update(readFileSync(file));
|
|
291
274
|
const jar = statSync(config.jar);
|
|
292
275
|
hash.update(JSON.stringify([config.jar, jar.size, jar.mtimeMs, realpathSync(config.java)]));
|
|
293
276
|
return hash.digest('hex').slice(0, 24);
|
|
@@ -546,16 +529,16 @@ class LocalJvm {
|
|
|
546
529
|
// The child gets its OWN fds on the fifos, closed here once it holds them.
|
|
547
530
|
const childIn = openSync(join(run, IN_FIFO), 'r+');
|
|
548
531
|
const childOut = openSync(join(run, OUT_FIFO), 'r+');
|
|
549
|
-
//
|
|
550
|
-
//
|
|
551
|
-
// is appended after it because the sketch's `argv(dir, size)` carries no host id,
|
|
552
|
-
// `forgeEngineRuntime`'s doc names that gap.
|
|
532
|
+
// The flags and the `child_process.spawn` call both come from `forgeEngineRuntime`; "--host
|
|
533
|
+
// hostId" is appended because the sketch's `argv(dir, size)` carries no host id.
|
|
553
534
|
const runtime = forgeEngineRuntime(config, log);
|
|
554
|
-
const bridge = bridgeLaunch(config, log);
|
|
555
|
-
const argv = [...runtime.argv(run, { memoryMb: source.xmxMb }), '--host', hostId];
|
|
556
535
|
let engineProcess;
|
|
557
536
|
try {
|
|
558
|
-
engineProcess = runtime.spawn(argv, run, { stdin: childIn, stdout: childOut, stderr: stderrFd });
|
|
537
|
+
engineProcess = runtime.spawn([...runtime.argv(run, { memoryMb: source.xmxMb }), '--host', hostId], run, { stdin: childIn, stdout: childOut, stderr: stderrFd });
|
|
538
|
+
}
|
|
539
|
+
catch (err) {
|
|
540
|
+
// A bridge that does not compile: the launch fails as a spawn that failed would.
|
|
541
|
+
throw new Error(`the JVM could not be started: ${err.message}`, { cause: err });
|
|
559
542
|
}
|
|
560
543
|
finally {
|
|
561
544
|
for (const fd of [childIn, childOut, stderrFd])
|
|
@@ -564,7 +547,7 @@ class LocalJvm {
|
|
|
564
547
|
this.engineProcess = engineProcess;
|
|
565
548
|
this.pid = engineProcess.pid;
|
|
566
549
|
live.add(this);
|
|
567
|
-
log({ evt: 'jvm-spawned', id: hostId, pid: this.pid, run
|
|
550
|
+
log({ evt: 'jvm-spawned', id: hostId, pid: this.pid, run });
|
|
568
551
|
writeFileAtomicSync(join(run, LAUNCH_RECORD_FILE), `${JSON.stringify({ hostId, pid: this.pid, startedAt: new Date().toISOString() })}\n`);
|
|
569
552
|
this.read();
|
|
570
553
|
engineProcess.onError((err) => this.finish(`the JVM could not be started: ${err.message}`, { code: null, signal: null }));
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hadoku/game-server",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"gitHead": "
|
|
3
|
+
"version": "0.1.233",
|
|
4
|
+
"gitHead": "eb3903629df79714ccc9ebd71736519172ff73ec",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"description": "The server parts any hosted game shares, above the kernel: the app config and edge auth, the room core (identity, seats, sessions, membership, the room list, the generic room routes), match hosting (the host contract, local and remote JVMs, placement, the start queue, recordings, the in-process and relay runtimes), streams, erase, telemetry and usage. Knows no game; Magic plugs in from apps/server. MIT; imports only node built-ins, express, socket.io, @wolffm/* and the platform packages.",
|
|
@@ -16,9 +16,9 @@
|
|
|
16
16
|
"play/remote/"
|
|
17
17
|
],
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@wolffm/host-wire": "npm:@hadoku/host-wire@0.1.
|
|
20
|
-
"@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.
|
|
21
|
-
"@wolffm/service-kernel": "npm:@hadoku/service-kernel@0.1.
|
|
19
|
+
"@wolffm/host-wire": "npm:@hadoku/host-wire@0.1.233",
|
|
20
|
+
"@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.233",
|
|
21
|
+
"@wolffm/service-kernel": "npm:@hadoku/service-kernel@0.1.266",
|
|
22
22
|
"@wolffm/prefs-client": "npm:@hadoku/prefs-client@^1.2.3",
|
|
23
23
|
"@wolffm/rooms-protocol": "npm:@hadoku/rooms-protocol@^0.45.152",
|
|
24
24
|
"@wolffm/rooms-server": "npm:@hadoku/rooms-server@^0.45.152",
|