GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(shared): port checks no longer fail on hosts with IPv6 disabled (… · pingdotgg/t3code@74904e3

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages/shared/src
    • Net.test.ts
    • Net.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/shared/src/Net.test.ts‎

Copy file name to clipboardExpand all lines: packages/shared/src/Net.test.ts
+28Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as NodeNet from "node:net";
22

33
import { assert, describe, it } from "@effect/vitest";
44
import * as Effect from "effect/Effect";
5+
import { vi } from "vite-plus/test";
56

67
import * as NetService from "./Net.ts";
78

@@ -54,6 +55,33 @@ it.layer(NetService.layer)("NetService", (it) => {
5455
}),
5556
);
5657

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+
5785
it.effect("isPortAvailableOnLoopback reports false for an occupied port", () =>
5886
Effect.acquireUseRelease(
5987
openServer("127.0.0.1"),
Collapse file

‎packages/shared/src/Net.ts‎

Copy file name to clipboardExpand all lines: packages/shared/src/Net.ts
+5-5Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,6 @@ export class NetService extends Context.Service<NetService, NetServiceShape>()(
4444

4545
/** @public Service construction is part of the canonical Effect module API. */
4646
export const make = () => {
47-
/**
48-
* `EADDRNOTAVAIL` is treated as available so IPv6-absent hosts don't fail
49-
* loopback availability checks.
50-
*/
5147
const canListenOnHost = (port: number, host: string): Effect.Effect<boolean> =>
5248
Effect.callback<boolean>((resume) => {
5349
const server = NodeNet.createServer();
@@ -62,7 +58,11 @@ export const make = () => {
6258
server.unref();
6359

6460
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+
) {
6666
settle(true);
6767
return;
6868
}

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.