fix(server): crash on startup when PORT is 10000 or higher - #128
Open
YAMRAJ13y wants to merge 1 commit into
Open
fix(server): crash on startup when PORT is 10000 or higher#128YAMRAJ13y wants to merge 1 commit into
YAMRAJ13y wants to merge 1 commit into
Conversation
The startup banner padded each row with hand-counted `String.repeat()`
arithmetic that assumed a 4-digit port. For any port in the 10000-65535
range the health-check row evaluated to `' '.repeat(-1)`, which throws:
$ PORT=10000 node server.mjs
[Crucix] FATAL — Server failed to start:
RangeError: Invalid count value: -1
at String.repeat (<anonymous>)
at start (server.mjs:417:59)
This happens before `app.listen()`, so the server never binds. The error
does not mention the port, and under the `restart: unless-stopped` policy
in docker-compose.yml it becomes a silent crash loop. README.md and
.env.example both document PORT as a free-form override.
Replace the hand-counted padding with a `renderBanner()` helper that
derives the frame width from its own contents. This also fixes two
existing cosmetic bugs: the box was already misaligned by 1-2 columns on
five of six rows at the default port, and a naive minimal fix would have
truncated the health URL to `/api/healt` for 5-digit ports.
Validated with PORT=80, 3117, 10000 and 65535, and with a longer provider
name and 3-digit refresh interval. Existing test suite unaffected
(45 pass, 1 skipped).
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
node server.mjscrashes before the server binds wheneverPORTis 10000 or higher. The startup banner is rebuilt so its frame width is derived from its contents instead of hand-counted padding.Why
The banner padded each row with
String.repeat()arithmetic that assumed a 4-digit port. For any port in the 10000–65535 range the health-check row evaluates to' '.repeat(-1), which throws:This happens before
app.listen(), so the server never binds and the dashboard never comes up. Two things make it hard to diagnose:restart: unless-stoppedindocker-compose.ymlit becomes a silent crash loopPORTis documented as a free-form override in bothREADME.mdand.env.example, anddocker-compose.ymlmaps${PORT:-3117}, so 10000+ is a supported configuration today.While fixing it I found the same hand-counted padding was already producing wrong output at the default port — the right border was misaligned by 1–2 columns on five of the six rows:
A minimal
Math.max(0, …)guard would stop the crash but truncate the health URL tohttp://localhost:10000/api/healtfor 5-digit ports, sorenderBanner()computes the width from the longest row instead. Output is unchanged at the default port apart from the border now lining up:Scope
Validation
Config and Docs
.env.exampleupdated if needed — not needed,PORTalready documentedREADME.mdupdated if behavior changed — not needed, this restores documented behaviorNotes
The banner still reads
26 Sourceswhileapis/briefing.mjswires 29 andREADME.mdsays 27. That mismatch is already covered by #124 and #84, so I left it alone to keep this diff to one bug.