惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

GbyAI
GbyAI
阮一峰的网络日志
阮一峰的网络日志
G
Google Developers Blog
J
Java Code Geeks
Blog — PlanetScale
Blog — PlanetScale
大猫的无限游戏
大猫的无限游戏
云风的 BLOG
云风的 BLOG
Vercel News
Vercel News
L
LangChain Blog
Hugging Face - Blog
Hugging Face - Blog
T
The Blog of Author Tim Ferriss
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Stack Overflow Blog
Stack Overflow Blog
P
Proofpoint News Feed
腾讯CDC
博客园_首页
博客园 - 聂微东
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
M
MIT News - Artificial intelligence
WordPress大学
WordPress大学
D
DataBreaches.Net
Microsoft Security Blog
Microsoft Security Blog
有赞技术团队
有赞技术团队
博客园 - 叶小钗

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
fix(infra): probe 127.0.0.1 in ensurePortAvailable to det...
Pandah97 · 2026-06-18 · via Recent Commits to openclaw:main
Original file line numberDiff line numberDiff line change

@@ -30,7 +30,9 @@ vi.mock("openclaw/plugin-sdk/ssrf-runtime-internal", () => ({

3030

registerManagedProxyBrowserCdpBypass: registerManagedProxyBrowserCdpBypassMock,

3131

}));

3232
33-

const ensurePortAvailableMock = vi.hoisted(() => vi.fn(async () => {}));

33+

const ensurePortAvailableMock = vi.hoisted(() =>

34+

vi.fn<(port: number, host?: string) => Promise<void>>(async () => {}),

35+

);

3436
3537

vi.mock("../infra/ports.js", () => ({

3638

ensurePortAvailable: ensurePortAvailableMock,

@@ -524,6 +526,7 @@ describe("chrome.ts internal", () => {

524526

color: "#FF4500",

525527

cdpPort,

526528

cdpUrl: `http://127.0.0.1:${cdpPort}`,

529+

cdpHost: "127.0.0.1",

527530

cdpIsLoopback: true,

528531

}) as unknown as ResolvedBrowserProfile;

529532

@@ -559,8 +562,33 @@ describe("chrome.ts internal", () => {

559562

await expect(launchOpenClawChrome(makeResolved(), profile)).rejects.toThrow(

560563

/No supported browser found/,

561564

);

565+

expect(ensurePortAvailableMock).toHaveBeenCalledWith(51111, "127.0.0.1");

562566

});

563567
568+

it.each([

569+

{ cdpUrl: "http://[::1]:51111", configuredProbeHost: "::1" },

570+

{ cdpUrl: "http://localhost:51111", configuredProbeHost: "localhost" },

571+

])(

572+

"checks Chrome's IPv4 bind and the configured $configuredProbeHost endpoint",

573+

async ({ cdpUrl, configuredProbeHost }) => {

574+

vi.spyOn(fs, "existsSync").mockReturnValue(false);

575+

const portBusy = new Error("Port is already in use.");

576+

portBusy.name = "PortInUseError";

577+

ensurePortAvailableMock.mockImplementation(async (_port, host) => {

578+

if (host === configuredProbeHost) {

579+

throw portBusy;

580+

}

581+

});

582+

const profile = { ...makeProfile(51111), cdpUrl };

583+
584+

await expect(launchOpenClawChrome(makeResolved(), profile)).rejects.toThrow(portBusy);

585+

expect(ensurePortAvailableMock.mock.calls).toEqual([

586+

[51111, "127.0.0.1"],

587+

[51111, configuredProbeHost],

588+

]);

589+

},

590+

);

591+
564592

it("completes successfully when Chrome reports /json/version and CDP is reachable", async () => {

565593

// Mock executable discovery to a truthy path.

566594

vi.spyOn(fs, "existsSync").mockImplementation((p) => {

Original file line numberDiff line numberDiff line change

@@ -633,8 +633,19 @@ async function ensureManagedChromePortAvailable(

633633

profile: ResolvedBrowserProfile,

634634

userDataDir: string,

635635

): Promise<void> {

636+

const configuredHost = new URL(profile.cdpUrl).hostname.replace(/^\[|\]$/g, "");

637+

const probeHosts =

638+

configuredHost === "127.0.0.1" ? [configuredHost] : ["127.0.0.1", configuredHost];

639+

const ensureProbeHostsAvailable = async () => {

640+

for (const host of probeHosts) {

641+

await ensurePortAvailable(profile.cdpPort, host);

642+

}

643+

};

644+
645+

// Chromium tries IPv4 loopback first, while OpenClaw polls the configured endpoint.

646+

// Probe both so neither Chrome's bind nor the later readiness check can be captured.

636647

try {

637-

await ensurePortAvailable(profile.cdpPort);

648+

await ensureProbeHostsAvailable();

638649

return;

639650

} catch (err) {

640651

const exe = resolveBrowserExecutable(resolved, profile);

@@ -645,7 +656,7 @@ async function ensureManagedChromePortAvailable(

645656

throw err;

646657

}

647658

}

648-

await ensurePortAvailable(profile.cdpPort);

659+

await ensureProbeHostsAvailable();

649660

}

650661
651662

function chromeLaunchHints(params: {

Original file line numberDiff line numberDiff line change

@@ -78,6 +78,19 @@ describe("ports helpers", () => {

7878

});

7979

});

8080
81+

it("ensurePortAvailable rejects when an explicitly scoped IPv4 loopback is busy", async () => {

82+

const server = net.createServer();

83+

const address = await listenServer(server, 0, "127.0.0.1");

84+

if (!address) {

85+

return;

86+

}

87+

const port = address.port;

88+

await expect(ensurePortAvailable(port, "127.0.0.1")).rejects.toBeInstanceOf(PortInUseError);

89+

await new Promise<void>((resolve) => {

90+

server.close(() => resolve());

91+

});

92+

});

93+
8194

it("handlePortError exits nicely on EADDRINUSE", async () => {

8295

const runtime = {

8396

error: vi.fn(),

Original file line numberDiff line numberDiff line change

@@ -36,10 +36,12 @@ export async function describePortOwner(port: number): Promise<string | undefine

3636

return formatPortDiagnostics(diagnostics).join("\n");

3737

}

3838
39-

export async function ensurePortAvailable(port: number): Promise<void> {

39+

/** Probes Node's wildcard bind by default; callers may scope checks to their owned interface. */

40+

export async function ensurePortAvailable(port: number, host?: string): Promise<void> {

4041

// Detect EADDRINUSE early with a friendly message.

4142

try {

42-

await tryListenOnPort({ port });

43+

const probe = host ? { port, host } : { port };

44+

await tryListenOnPort(probe);

4345

} catch (err) {

4446

if (isErrno(err) && err.code === "EADDRINUSE") {

4547

throw new PortInUseError(port);