[Bug] Pool exits at startup when the delegate lookup fails

Open
#18 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
70/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
javascript, node.js
Domain
api, backend

Research direction

Start in server/src/app.js at initDelegate() (L131-L138) and server/src/modules/store.js L313. Read how updateDelegate() returns undefined and triggers process.exit. Implement bounded retry for transport or node-readiness failures, keeping the web server up and /api/health at 'starting'. Done when the pool no longer exits on transient delegate lookup failure and reports starting until a node answers.

Written by the indexing model from the issue text.

Description

bug NodeJS
Summary

A failed delegate lookup at startup is fatal: initDelegate() exits the process for any unsuccessful getDelegate response, so a node that is reachable but not finished loading is treated exactly like an account that is not a delegate. Under a process manager the pool is then restarted repeatedly until a node serves delegate data.

Steps to reproduce
  1. Run a pool whose node_ADM list reaches no node that can answer a delegate query yet. The usual case is a host where the pool and its local ADAMANT node start together after a reboot: the node answers /api/node/status while it is still rebuilding its memory tables, and answers the delegate query only later.
  2. Start the pool under PM2 or systemd (no TTY).
  3. Watch the log and the restart counter.
Expected behavior

The pool stays up, retries the lookup with a bounded backoff, and reports status: "starting" through /api/health until a node answers. It already has both pieces: a multi-node list with failover (remote nodes next to http://localhost:36666) and a starting state in the health snapshot. A hard exit should be reserved for a response that actually proves the account is not a delegate, because that is a configuration error an operator must fix.

Actual behavior

initDelegate() (server/src/app.js#L131-L138) calls store.updateDelegate() (server/src/modules/store.js#L313), which returns undefined whenever getDelegateResponse.success is false, whatever the reason. The caller logs Failed to get delegate for <address>. Cannot start Pool. and calls process.exit(EXIT_CODE_ERROR).

Consequences on a host where the node and the pools boot together:

  • The process manager restarts the pool a few times at every boot. The restart counter grows for a reason that is not a fault, which hides a genuine restart loop from monitoring that alerts on it.
  • An encrypted pool comes back locked after each restart, so the unnecessary restarts multiply operator unlocks.
  • Nothing in /api/health reflects the situation, because the process is gone instead of reporting starting.

A contributing factor sits in adamant-api 3.1.0, and may deserve its own issue there:

  • NodeManager.updateNodes() calls this.ready() unconditionally (src/helpers/healthCheck.ts#L143-L145), so onReady fires even after chooseNode() bailed out with "All of N nodes are unavailable".
  • checkNodes() (same file, #L327-L345) counts a node as active once it answers /api/node/status, without looking at loaded or syncing.

Together they make the pool set setNodeReady(true) and start the delegate lookup while no node can serve it, which turns the fatal exit above from an edge case into something that happens at every boot.

Environment

Reproduced with pool v3.1.0 under PM2 on Ubuntu 26.04 LTS, with the pool and an ADAMANT node on the same host. The code path is unchanged on dev (3.1.1).

Suggested fix

In initDelegate(), retry updateDelegate() with a bounded backoff while the lookup fails for a transport or node-readiness reason, keep the web server and the control socket running, and keep /api/health at starting. Exit only for a response that identifies the account as not a delegate. UPDATE_DELEGATE_INTERVAL already re-runs store.updateAll() once the pool is up, so the startup path is the only place that needs the retry.

Dominant language
JavaScript
Stars
512
Forks
9
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Adamant-im/pool

All issues in Adamant-im/pool

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.