Skip to content

Commit b2509f8

Browse files
committed
fix(plugin-hono-server): a request for port 0 no longer warns that port 0 is in use
kernel:listening compared the requested port with the bound one and warned whenever they differed. Port 0 asks for a kernel-assigned port, so the two can never match and nothing was in use. The warning now fires only for a non-zero request the adapter's EADDRINUSE walk moved; the started line already names the bound port. The released-port ledger's reason for serve-port-drift-notice.e2e.test.ts quoted that warning as why its negative arm cannot use --port 0. It now states only the arm's subject: a non-zero request, which --port 0 cannot ask. Claude-Session: https://claude.ai/code/session_01SYEJqDL3NXxrJRBVqaMu9T Co-authored-by: Claude <noreply@anthropic.com>
1 parent c18c1ff commit b2509f8

3 files changed

Lines changed: 17 additions & 3 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@objectstack/plugin-hono-server': patch
3+
---
4+
5+
fix(plugin-hono-server): a request for port 0 no longer warns that port 0 is in use
6+
7+
Clause-②: no (no export, option or type moves: a log line stops firing for a legal request)
8+
9+
- **What changed.** `HonoServerPlugin`'s `kernel:listening` hook compared the requested port with the bound one and warned `Port 0 is in use, using port N instead` whenever they differed. Port `0` asks for a kernel-assigned port, so the two can never match and nothing was in use. Every `os serve --port 0` boot printed that warning under the banner's Boot diagnostics, at the default log level and at `info`. The warning now fires only for a non-zero request that the adapter moved to another port.
10+
- **Unchanged.** A kernel-assigned boot prints the existing `HTTP server started successfully` line, which already names the bound port, and nothing else. A non-zero request whose port is held still warns, naming the requested and the bound port.

‎packages/cli/test/released-port-production-spawn.pin.test.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@ const RELEASED_DRAW_LEDGER: Readonly<Record<string, { draws: number; why: string
8686
'serve-port-drift-notice.e2e.test.ts': {
8787
draws: 1,
8888
why: 'the NEGATIVE arm is a boot that binds exactly the non-zero port it asked for and says '
89-
+ 'nothing about ports; `--port 0` asks for no port, and that boot prints plugin-hono-server\'s '
90-
+ '"Port 0 is in use, using port N instead" (#24387)',
89+
+ 'nothing about ports; a non-zero request is its subject, which `--port 0` cannot ask',
9190
},
9291
'serve-publishes-bound-port.e2e.test.ts': {
9392
draws: 2,

‎packages/plugins/plugin-hono-server/src/hono-plugin.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,12 @@ export class HonoServerPlugin implements Plugin {
709709
await this.server.listen(port);
710710

711711
const actualPort = this.server.getPort();
712-
if (actualPort !== port) {
712+
// Port 0 is a request for a kernel-assigned port, not a busy one:
713+
// `listen(0)` can never bind the number it was given, so a mismatch
714+
// there says nothing about a port in use. The started line below
715+
// already names the bound port. Only a non-zero request that the
716+
// adapter's EADDRINUSE walk moved is a drift worth a warning.
717+
if (port !== 0 && actualPort !== port) {
713718
ctx.logger.warn(`Port ${port} is in use, using port ${actualPort} instead`);
714719
}
715720
ctx.logger.info('HTTP server started successfully', {

0 commit comments

Comments
 (0)