@devries-cameron20 / t3code-1 / commits / 74904e36ee
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(shared): port checks no longer fail on hosts with IPv6 disabled (#15044)

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>

mr-joom committed Oct 19, 2026 at 08:27 UTC 74904e36ee4e907798d631683dbea296f13d3b7f
2 files changed +33 -5
packages/shared/src/Net.test.ts
+28
@@ -2,6 +2,7 @@ import * as NodeNet from "node:net";
2
3 import { assert, describe, it } from "@effect/vitest";
4 import * as Effect from "effect/Effect";
5 +import { vi } from "vite-plus/test";
6
7 import * as NetService from "./Net.ts";
8
@@ -54,6 +55,33 @@ it.layer(NetService.layer)("NetService", (it) => {
55 }),
56 );
57
58 + it.effect.each(["EAFNOSUPPORT", "EADDRNOTAVAIL"])(
59 + "keeps ports available when IPv6 binds fail with %s",
60 + (code) =>
61 + Effect.gen(function* () {
62 + const net = yield* NetService.NetService;
63 + const port = yield* net.reserveLoopbackPort();
64 + const listen = NodeNet.Server.prototype.listen;
65 + const spy = vi.spyOn(NodeNet.Server.prototype, "listen").mockImplementation(function (
66 + this: NodeNet.Server,
67 + ...args
68 + ) {
69 + const [options] = args;
70 + if (options?.host === "::1" || options?.host === "::") {
71 + process.nextTick(() => this.emit("error", Object.assign(new Error(code), { code })));
72 + return this;
73 + }
74 + return listen.apply(this, args);
75 + });
76 + try {
77 + assert.equal(yield* net.isPortAvailableOnLoopback(port), true);
78 + assert.equal(yield* net.canListenOnHost(port, "::"), true);
79 + } finally {
80 + spy.mockRestore();
81 + }
82 + }),
83 + );
84 +
85 it.effect("isPortAvailableOnLoopback reports false for an occupied port", () =>
86 Effect.acquireUseRelease(
87 openServer("127.0.0.1"),
packages/shared/src/Net.ts
+5 -5
@@ -44,10 +44,6 @@ export class NetService extends Context.Service<NetService, NetServiceShape>()(
44
45 /** @public Service construction is part of the canonical Effect module API. */
46 export const make = () => {
47 - /**
48 - * `EADDRNOTAVAIL` is treated as available so IPv6-absent hosts don't fail
49 - * loopback availability checks.
50 - */
47 const canListenOnHost = (port: number, host: string): Effect.Effect<boolean> =>
48 Effect.callback<boolean>((resume) => {
49 const server = NodeNet.createServer();
@@ -62,7 +58,11 @@ export const make = () => {
58 server.unref();
59
60 server.once("error", (cause) => {
65 - if (isErrnoExceptionWithCode(cause) && cause.code === "EADDRNOTAVAIL") {
61 + // Missing IPv6 addresses or kernel support do not mean the port is occupied.
62 + if (
63 + isErrnoExceptionWithCode(cause) &&
64 + (cause.code === "EADDRNOTAVAIL" || cause.code === "EAFNOSUPPORT")
65 + ) {
66 settle(true);
67 return;
68 }