You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Fail fast when the daemon isn't running instead of waiting the full 20s RPC connect timeout #178
When no daemon is listening at --pkcRpcUrl, every command that connects to it waits the full 20 seconds before reporting the daemon isn't running, even though the connection is refused right away:
$ time bitsocial community list --pkcRpcUrl ws://127.0.0.1:1
Error: Could not connect to the daemon at ws://127.0.0.1:1/. Is it running? Start it with: bitsocial daemon
real 0m20.569s
This affects every caller of BaseCommand._connectToPkcRpc (src/cli/base-command.ts): community list/get/create/edit/delete/start/stop/export, and the in-use check in challenge remove and page-sort remove (#176, #177).
Cause
pkc-js reports the refused connection almost immediately and then retries every second, until its own ERR_FAILED_TO_OPEN_CONNECTION_TO_RPC at about 20s:
197 ms error connect ECONNREFUSED 127.0.0.1:1
1199 ms error connect ECONNREFUSED 127.0.0.1:1
...
4205 ms error connect ECONNREFUSED 127.0.0.1:1
20207 ms error ERR_FAILED_TO_OPEN_CONNECTION_TO_RPC
_connectToPkcRpc collects those error events but only looks at them when its 20s timer fires. It only resolves early on communitieschange.
Proposal
Fail fast when the connection is refused: reject once ECONNREFUSED keeps repeating for a short grace period (about 2s). The grace period covers a daemon that is still starting, since it binds the RPC port partway through startup. Then throw the existing "Could not connect to the daemon… Is it running?" message.
Keep the 20s timeout for everything else: a host that accepts the connection but doesn't answer, slow remote daemons, and ERR_RPC_AUTH_REQUIRED, which is already rethrown as is.
Destroy the pkc instance on rejection so its retry loop doesn't keep the process alive.
Done when
A command pointed at a closed local port fails in about 2s instead of 20s, with the same message.
A test covers it (for example, community list --pkcRpcUrl ws://127.0.0.1:1 finishes well under 20s), plus one showing that a daemon starting within the grace period still connects.
The "refuses to remove when the daemon cannot be reached" tests in test/cli/challenge.test.ts and test/cli/page-sort.test.ts (about 20s each today) speed up accordingly.
Activity