Faucet top-up intermittently fails or hangs: local state query sent while agent is Idle

Open
#221 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
25/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
java
Domain
backend

Research direction

Start at AddressController.topup, which discards the writer output, and AccountService.topup, which turns logging off; the stack trace points into LocalStateQueryClient.executeQuery's auto-acquire path. Run the reproduction loop with LOGGING_LEVEL_ROOT=DEBUG under taskset -c 0,1 and look for Current state [Idle] in the log. Done means top-ups stop returning 500 or hanging under that load, and a timed-out query fails instead of waiting forever. The race itself sits in the yaci library classes, so confirm the fix against the agent's state transitions before changing this repo.

Written by the indexing model from the issue text.

Description

Problem

Under CPU pressure, about 1 in 10 calls to POST /local-cluster/api/addresses/topup either fail with 500 {"status":false,"message":"Topup failed"} in ~100 ms, or hang (no response after 60s). We see it in CI on 2-core GitHub runners, where it makes devnet-based integration tests flaky.

With LOGGING_LEVEL_ROOT=DEBUG (otherwise AccountService.topup turns logging off, and AddressController discards the writer output), every failed top-up logs:

ERROR c.b.c.y.l.service.AccountService - Error
java.lang.IllegalStateException: Current state [Idle] doesn't support this message : MsgQuery(query=com.bloxbean.cardano.yaci.core.protocol.localstate.queries.UtxoByAddressQuery@16db8274, ...)
	at com.bloxbean.cardano.yaci.core.protocol.State.verifyMessageType(State.java:35)
	at com.bloxbean.cardano.yaci.core.protocol.localstate.LocalStateQueryAgent.query(LocalStateQueryAgent.java:137)
	at com.bloxbean.cardano.yaci.helper.LocalStateQueryClient.lambda$executeQuery$3(LocalStateQueryClient.java:176)
	...
	at com.bloxbean.cardano.yaci.helper.LocalStateQueryClient$1.acquired(LocalStateQueryClient.java:67)
	at com.bloxbean.cardano.yaci.core.protocol.localstate.LocalStateQueryAgent.onMessageAcquired(LocalStateQueryAgent.java:124)
	at com.bloxbean.cardano.yaci.core.protocol.localstate.LocalStateQueryAgent.processResponse(LocalStateQueryAgent.java:87)
	at com.bloxbean.cardano.yaci.core.protocol.Agent.receiveResponse(Agent.java:44)

preceded by ERROR reactor.core.publisher.Operators - Operator called default onErrorDropped with the same cause. When the error is dropped rather than delivered, the query's Mono never completes, which is presumably the hang.

So executeQuery's auto-acquire path sends the MsgQuery from the acquired callback while the agent still reports Idle. Reading the code, Agent.receiveResponse sets the new state before calling processResponse, so this looks like a race on the agent's state between the caller thread (acquire() / sendNextMessage()) and the Netty event loop, rather than a wrong transition. I haven't confirmed that part.

Reproduce

@bloxbean/yaci-devkit 0.12.0 on Linux x64, with the devkit restricted to 2 cores:

LOGGING_LEVEL_ROOT=DEBUG taskset -c 0,1 yaci-devkit up --enable-yaci-store > up.log 2>&1 &
# once the devnet is up:
for i in $(seq 30); do
  curl -s -m 60 -o /dev/null -w '%{http_code}\n' -X POST -H 'Content-Type: application/json' \
    -d '{"address":"addr_test1qrqfxwuz8rm0xvewfrp5eudgup24jsan8n22h3f6a7mavyjt0njqm4ykhhqzkdrq9ua8w0lhen8wsuuerexgsehn5u9syjlrxr","adaAmount":10}' \
    http://localhost:10000/local-cluster/api/addresses/topup
done
grep -c "Current state \[Idle\]" up.log

Two runs of 30–40 top-ups gave 3 failures each: in the first, one fast 500 and two hangs; in the second, three fast 500s. Without taskset, it rarely shows up locally.

Suggestions

  • Fix the race in the local state query client (e.g. make the agent's state transitions and the send path synchronize on the same lock, or have executeQuery send the query from the event loop after the state has moved to Acquired).
  • Separately, it would help if AddressController.topup returned the error message instead of discarding it (msg -> {}), and if a top-up that can't get a query result within its timeout failed instead of hanging.

Related, same wrapper version: #220.

Dominant language
Java
Stars
70
Forks
21
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

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 bloxbean/yaci-devkit

All issues in bloxbean/yaci-devkit

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.