Repository navigation
Description
Bug Report
This is a continuation of the investigation in issue #521. That issue reported the error:
ERR Won’t start a peer – switch is not running module=p2p peer={“Data”:{}, “Logger”:{}}
Unlike that issue, we discovered this error does not appear consistently in the logs.
Instead, the node simply falls out of sync with the network, and it is likely caused by the node losing its peers without apparent reason.
Setup
CometBFT version (use cometbft version or git rev-parse --verify HEAD if installed from source): v0.34.24
Have you tried the latest version: no
ABCI app (name for built-in, URL for self-written if it's publicly available): (osmosis v15.1.0)
Environment:
- OS (e.g. from /etc/os-release): 15.1.0-alpine
Config
config.toml
proxy_app = "tcp://127.0.0.1:26658"
moniker = "osmosis"
fast_sync = true
db_backend = "goleveldb"
db_dir = "data"
log_level = "info"
log_format = "plain"
genesis_file = "config/genesis.json"
priv_validator_key_file = "config/priv_validator_key.json"
priv_validator_state_file = "data/priv_validator_state.json"
priv_validator_laddr = ""
node_key_file = "config/node_key.json"
abci = "socket"
filter_peers = false
[rpc]
laddr = "tcp://0.0.0.0:26657"
cors_allowed_origins = ["*"]
cors_allowed_methods = ['HEAD', 'GET', 'POST', 'DELETE', 'OPTIONS', 'PATCH', 'PUT',]
cors_allowed_headers = ["Origin", "Accept", "Content-Type", "X-Requested-With", "X-Server-Time", "Accept-Encoding"]
grpc_laddr = ""
grpc_max_open_connections = 900
unsafe = false
max_open_connections = 900
max_subscription_clients = 100
max_subscriptions_per_client = 5
experimental_subscription_buffer_size = 200
experimental_websocket_write_buffer_size = 200
experimental_close_on_slow_client = false
timeout_broadcast_tx_commit = "10s"
max_body_bytes = 1000000
max_header_bytes = 1048576
tls_cert_file = ""
tls_key_file = ""
pprof_laddr = "localhost:6060"
[p2p]
laddr = "tcp://0.0.0.0:26656"
external_address = ""
seeds = "[edited]"
persistent_peers = ""
upnp = false
addr_book_file = "config/addrbook.json"
addr_book_strict = true
max_num_inbound_peers = 320
max_num_outbound_peers = 160
unconditional_peer_ids = ""
persistent_peers_max_dial_period = "0s"
flush_throttle_timeout = "100ms"
max_packet_msg_payload_size = 1024
send_rate = 5120000
recv_rate = 5120000
pex = true
#
seed_mode = false
private_peer_ids = ""
allow_duplicate_ip = false
handshake_timeout = "20s"
dial_timeout = "3s"
[mempool]
recheck = true
broadcast = true
wal_dir = ""
size = 10000
max_txs_bytes = 1073741824
cache_size = 10000
keep-invalid-txs-in-cache = false
max_tx_bytes = 1048576
max_batch_bytes = 0
[statesync]
enable = false
rpc_servers = ""
trust_height = 0
trust_hash = ""
trust_period = "112h0m0s"
discovery_time = "15s"
temp_dir = ""
chunk_request_timeout = "10s"
chunk_fetchers = "4"
[fastsync]
version = "v0"
[consensus]
wal_file = "data/cs.wal/wal"
timeout_propose = "3s"
timeout_propose_delta = "500ms"
timeout_prevote = "1s"
timeout_prevote_delta = "500ms"
timeout_precommit = "1s"
timeout_precommit_delta = "500ms"
timeout_commit = "5s"
double_sign_check_height = 0
skip_timeout_commit = false
create_empty_blocks = true
create_empty_blocks_interval = "0s"
peer_gossip_sleep_duration = "100ms"
peer_query_maj23_sleep_duration = "2s"
[tx_index]
indexer = "kv"
[instrumentation]
prometheus = true
prometheus_listen_addr = ":26660"
max_open_connections = 3
namespace = "tendermint"What happened?
Node stops processing blocks and falls out of sync with the network. Likely caused by lost peers, but unclear.
What did you expect to happen?
The node continues processing blocks, remains in sync with the networks.
How to reproduce it
Unclear.
Logs
Logs with some editing here: https://gist.github.com/adizere/b60b4483328f70a9ded7a02eca414fd2
Some interesting parts of the logs
Successful block processing:
Process block: 9527565
5:04AM INF Timed out dur=4805.514376 height=9527565 module=consensus round=0 step=1
5:04AM INF received proposal module=consensus proposal={"Type":32,"block_id":{"hash":"8217A2B0C27E06BCD12608D320EBCF319D365706518A5BB2B5DEB62DF5C2EC7A","parts":{"hash":"D1162FA845D6B218A3EBBE9192184997B7CC879A6C3176EF31D9FD85205F2639","total":1}},"height":9527565,"pol_round":-1,"round":0,"signature":"/GB+VdFC4t5MJrMfJ2ZXcRA9Kyjy8iJe9dt8w3b9Ys7sp+RW6+3nC7O49VUYVfI3z0bFXnmu9GXXG06xzv4lBQ==","timestamp":"2023-05-08T05:04:21.243840496Z"}
5:04AM INF received complete proposal block hash=8217A2B0C27E06BCD12608D320EBCF319D365706518A5BB2B5DEB62DF5C2EC7A height=9527565 module=consensus
5:04AM INF finalizing commit of block hash={} height=9527565 module=consensus num_txs=6 root=EDDBF0AB651E79247D405C92E94AC644784AF22D5E609007209C77A7D793ED93
5:04AM INF executed block height=9527565 module=state num_invalid_txs=0 num_valid_txs=6
5:04AM INF committed ABCI commit_hash=C322D21F224E192DBA0E6BEA0B119FF118F731AB7450DB7F50F0D9CDC46A2558 height=9527565 retain_height=0
5:04AM INF committed state app_hash=C322D21F224E192DBA0E6BEA0B119FF118F731AB7450DB7F50F0D9CDC46A2558 height=9527565 module=state num_txs=6
5:04AM INF indexed block exents height=9527565 module=txindex
The block after, at height 9527566 never finishes processing:
Process block: 9527566
5:04AM INF Timed out dur=4790.012085 height=9527566 module=consensus round=0 step=1
5:04AM INF received proposal module=consensus proposal={"Type":32,"block_id":{"hash":"327EF3DC5C1A687CF1DFE3F83212D78AEFF541B868AF1ACFA1FAAC601E5CE4EB","parts":{"hash":"7CDA70D452416E471DD3A092A79150EA3EC3B2AA9E3BA2F9CA7860E9EAC582AA","total":1}},"height":9527566,"pol_round":-1,"round":0,"signature":"U/dJgXx0tWCilcvTRmoL8hWf3Px6TrTppN/70g3AawK+ejLyqadrdJ3lOv2Xa35JHo5eE7JS8lbU9PwveY3PDg==","timestamp":"2023-05-08T05:04:27.10577461Z"}
5:04AM INF received complete proposal block hash=327EF3DC5C1A687CF1DFE3F83212D78AEFF541B868AF1ACFA1FAAC601E5CE4EB height=9527566 module=consensus
5:04AM INF finalizing commit of block hash={} height=9527566 module=consensus num_txs=10 root=C322D21F224E192DBA0E6BEA0B119FF118F731AB7450DB7F50F0D9CDC46A2558
5:04AM INF Timed out dur=1000 height=9527566 module=consensus round=0 step=5
grep by 'Ensure peers' overview
5:00AM INF Ensure peers module=pex numDialing=0 numInPeers=0 numOutPeers=26 numToDial=134
5:00AM INF Ensure peers module=pex numDialing=0 numInPeers=0 numOutPeers=28 numToDial=132
5:01AM INF Ensure peers module=pex numDialing=0 numInPeers=0 numOutPeers=28 numToDial=132
5:01AM INF Ensure peers module=pex numDialing=0 numInPeers=0 numOutPeers=29 numToDial=131
5:02AM INF Ensure peers module=pex numDialing=0 numInPeers=0 numOutPeers=31 numToDial=129
5:02AM INF Ensure peers module=pex numDialing=0 numInPeers=0 numOutPeers=31 numToDial=129
5:03AM INF Ensure peers module=pex numDialing=0 numInPeers=0 numOutPeers=31 numToDial=129
5:03AM INF Ensure peers module=pex numDialing=0 numInPeers=0 numOutPeers=32 numToDial=128
5:04AM INF Ensure peers module=pex numDialing=0 numInPeers=0 numOutPeers=32 numToDial=128
// Adi: This is where block height 9527566 fails to complete
5:04AM INF Ensure peers module=pex numDialing=0 numInPeers=0 numOutPeers=34 numToDial=126
5:05AM INF Ensure peers module=pex numDialing=0 numInPeers=0 numOutPeers=34 numToDial=126
5:05AM INF Ensure peers module=pex numDialing=0 numInPeers=0 numOutPeers=22 numToDial=138
5:06AM INF Ensure peers module=pex numDialing=0 numInPeers=0 numOutPeers=1 numToDial=159
5:06AM INF Ensure peers module=pex numDialing=0 numInPeers=0 numOutPeers=12 numToDial=148
5:07AM INF Ensure peers module=pex numDialing=0 numInPeers=0 numOutPeers=12 numToDial=148
5:07AM INF Ensure peers module=pex numDialing=0 numInPeers=0 numOutPeers=11 numToDial=149
// Adi: 0 connected peers
5:08AM INF Ensure peers module=pex numDialing=0 numInPeers=0 numOutPeers=0 numToDial=160
5:08AM INF Ensure peers module=pex numDialing=0 numInPeers=0 numOutPeers=18 numToDial=142
5:09AM INF Ensure peers module=pex numDialing=0 numInPeers=0 numOutPeers=18 numToDial=142
5:09AM INF Ensure peers module=pex numDialing=0 numInPeers=0 numOutPeers=20 numToDial=140
Acceptance criteria
- Confirm the root cause: the CacheKV store or IAVL deadlock in the SDK/app
- See context in the discussion of this issue
- confirmed here: Continue debugging the problem of node falling out of sync #815 (comment)
- Open follow-up issue to capture problem & requirements on (p2p + consensus + ABCI queries) sharing a single mutex
- other teams (including dYdX and Vocdoni) have signalled this problem to us separately
- tracked from Introduce relaxed ABCI concurrency models #88
Activity
cason commentedon May 8, 2023
It appears that the peers lost in the problematic section the log have the same reason:
I will check details of this logic. In short, every minute (60 seconds), a node send a ping to a peer and starts a pong timer with 45 seconds. If a pong message is not received by this deadline, this error is produced and the connection with the peer is closed. This is part of the MultiplexConnection, the node keeps one of those per connected peer.
adizere commentedon May 11, 2023
@sergio-mena and I spent a bit of time today debugging this.
We got access to a node that was symptomatic, running in Docker. The node was stuck at a block that was ~1hr old. We suspected the node is in a deadlock, since it still had peers connected. The symptom was similar to what I reported above (See the log snippet for block height
9527566). We did:docker attachto gain access to stdout/err of that machinekill -6 $PIDapp.mtx.LockDeliverTxAsync;x/staking/keeper, serving a query forValidatorDelegations.We informed the Osmosis team about the problem and waiting for feedback.
ValarDragon commentedon May 11, 2023
TY for investigating!!
The hypothesis right now is then that:
So my understanding is that the separate ideas for us to try would be:
?
adizere commentedon May 12, 2023
That matches my understanding, great summary!
This is more nuanced:
DeliverTxAsyncrequires the Lock on the same mutex that the external query is holdingI shared with Niccolo the full stacktrace. The relevant segment is below.
Relevant routine from stracktrace
It would be great if we can get a confirmation on the CacheKV store or IAVL deadlock.
This is something we will look into on our side. This issue with the global lock was a point of major feedback from another team.
ValarDragon commentedon May 15, 2023
I don't think this is a deadlock from either CacheKV or IAVL, or if it is, I don't see the second thing taking the deadlock. In the example:
Stack trace snippet
I've spent awhile looking at this, and I can't see any reason why this would deadlock. CacheKV locks:
This can't be triggerring at the target line, as that can call:
Will look through other functions here, but I don't think this is the cause right now. Other functions called here:
Nicco's also helping get more goroutine dumps so can cross-check for similarities
ValarDragon commentedon May 15, 2023
I've taken a node that stucks in this cycle, and periodically dump the goroutines. The one I'm looking at does continually have an instance of this
ValidatorDelegationsquery running, however it is running. (Which is suspicious) On every query, the goroutine ID changes, and the spot in which it is located changes. So I suspect there is no CacheKV or IAVL deadlock (or if there is, its not in thisValidatorDelegationsquery)In multiple goroutine dumps, I'm not seeing anything from
store/iavl/cachekvstuck on a mutex, so it doesn't feel like its from there.Going to try to be careful that theres no way this query could be infinitely looping somehow
ValarDragon commentedon May 15, 2023
I think I found the issue state machine side!
So if I look into these halt goroutines, there are many piled up queries. I was manualy taking goroutine dumps for a node, doing nothing else, and then eventually it started working. Looking at these, every time one
ValidatorDelegationswas running. However it was a different PID everytime. And if we count how many queries were going on, its:Each of these queries can take a long time because the SDK does a bad job of limiting their resource consumption (will work on fixing this). You can make this query take tens of minutes.
So my current working theory is we had many competing mutexes on the query connection. And other things in Tendermint were competing for the same mutex, causing the observed system issues?
sergio-mena commentedon May 16, 2023
In case it helps, when @adizere and I found the goroutine holding the lock last Thu, we observed that the routine was in "runnable" state, not waiting on a lock (check Adi's traceback above). So I'm 99% convinced it isn't a deadlock but an infinite loop or, as you say @ValarDragon, a very inefficient loop, which (in the case we analyzed last Thu) had been holding the App's lock for over an hour, blocking everything else.
ValarDragon commentedon May 16, 2023
Can confirm, its a query that can take a few hours to execute
How do we get queries to not be on the same lock as consensus? (Separately going to work on better resource bounding this query)
adizere commentedon May 20, 2023
Great, thanks for confirming!
It seems like v0.36 attempted something with regard to removing fine-grained ABCI locks. We'll track this work specifically in #88; we'll scope down that issue or open a sub-issue. I will close this one as we answered the initial question.