Implement server lifecycle manager (lazy singleton) #128

Closed
opened 2026-08-30 10:22:03 +02:00 by SirStone · 3 comments
Owner

Wayfinder child of: #126

Implement the lazy singleton that starts the Tank Royale Java server on first use with -I flag, manages the process, and kills it on exit. Needs to find the server JAR, pick a free port, wait for ready.

Blocked by: nothing

Grilling Revisions

MAJOR CHANGE: External server, not embedded. The original spec assumed embedded server. Initial positions (-I flag) are incompatible with embeddedServer() mode — -I is a server CLI flag, not a BattleRunner API property.

Revised lifecycle:

  1. Framework starts java -jar $TANK_ROYALE_JAR -I --tps -1 --port PORT as a subprocess
  2. Random free port selected to avoid conflicts
  3. Trust BattleRunner's internal readiness wait (designed for external server). Add manual WebSocket poll only if proven flaky.
  4. Server stays alive for process lifetime (lazy singleton)
  5. addQuitProc kills server process on exit

JAR location: TANK_ROYALE_JAR env var. Fail fast with clear message if not set or JAR not found.

No -I flag on BattleRunner API — it's a server startup flag only. This is why external server is required.

**Wayfinder child of:** #126 Implement the lazy singleton that starts the Tank Royale Java server on first use with `-I` flag, manages the process, and kills it on exit. Needs to find the server JAR, pick a free port, wait for ready. **Blocked by:** nothing ### Grilling Revisions **MAJOR CHANGE: External server, not embedded.** The original spec assumed embedded server. Initial positions (`-I` flag) are incompatible with `embeddedServer()` mode — `-I` is a server CLI flag, not a BattleRunner API property. **Revised lifecycle:** 1. Framework starts `java -jar $TANK_ROYALE_JAR -I --tps -1 --port PORT` as a subprocess 2. Random free port selected to avoid conflicts 3. Trust BattleRunner's internal readiness wait (designed for external server). Add manual WebSocket poll only if proven flaky. 4. Server stays alive for process lifetime (lazy singleton) 5. `addQuitProc` kills server process on exit **JAR location**: `TANK_ROYALE_JAR` env var. Fail fast with clear message if not set or JAR not found. **No `-I` flag on BattleRunner API** — it's a server startup flag only. This is why external server is required.
SirStone added the wayfinder:task label 2026-08-30 10:22:03 +02:00
Author
Owner

Spec additions from grilling

  • Server startup timeout: 15s default. If server doesn't print ready signal within this, raise error.
  • Use addExitProc to kill server process on program exit (covers normal exit, exceptions, signals).
  • Use defer in any proc that starts the server as additional safety net.
## Spec additions from grilling - Server startup timeout: **15s** default. If server doesn't print ready signal within this, raise error. - Use `addExitProc` to kill server process on program exit (covers normal exit, exceptions, signals). - Use `defer` in any proc that starts the server as additional safety net.
Author
Owner

Dependency addition

Blocks: #130 (runBattle orchestrator), #134 (BattleRunner process lifecycle). Server must be running before either can operate.

## Dependency addition Blocks: #130 (runBattle orchestrator), #134 (BattleRunner process lifecycle). Server must be running before either can operate.
Author
Owner

Implemented in commit 57a1915.

Implemented in commit 57a1915.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: SirStone/SirRoboGarage#128