Skip to content

Flaky daemon test: KUBO_RPC_URL test still uses a one-shot fetch that races the pkc-js kubo restart (lineage #95) #133

Description

@Rinse12

Symptom

test/cli/daemon.test.tsbitsocial daemon KUBO_RPC_URL env vardaemon uses KUBO_RPC_URL env var to configure kubo bind address failed on macOS CI:

TypeError: fetch failed  ->  connect ECONNREFUSED 127.0.0.1:<kuboPort>
 ❯ test/cli/daemon.test.ts:757:25

Ubuntu passed in the same run; the suite passes locally. Seen on the CI run for PR #132 (a pkc-js 0.0.82 -> 0.0.83 bump whose lockfile diff touches nothing but pkc-js itself), so this is not caused by that upgrade.

Root cause

Identical to issue #95. startPkcDaemon resolves as soon as the daemon prints its Communities in data path banner, which does not guarantee kubo's HTTP API is currently listening. Since pkc-js 0.0.46, pkc-js rewrites kubo's Routing config and POSTs /shutdown on first connect, so the daemon restarts kubo around init — a brief window where the kubo API port refuses connections.

The test verifies kubo with a single, un-retried fetch that can land in that window:

const res = await fetch(`${daemon.kuboApiUrl}/bitswap/stat`, { method: "POST" });
expect(res.status).toBe(200);

The #95 fix only patched the two tests in the kills kubo on its own shutdown describe. This is the last remaining bare one-shot kubo check in the suite — everything else polls waitForKuboReady.

Fix

Use the existing retry helper:

const kuboReady = await waitForKuboReady(daemon.kuboApiUrl, 45000);
expect(kuboReady).toBe(true);

Fixed on PR #132.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions