Skip to content

Continue debugging the problem of node falling out of sync #815

Closed

Description

@adizere

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:

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

Activity

  1. added
    bug
    on May 8, 2023
  2. added this to the 2023-Q2 milestone on May 8, 2023
  3. self-assigned this
    on May 8, 2023
  4. cason commented on May 8, 2023

    @cason

    It appears that the peers lost in the problematic section the log have the same reason:

    5:05AM ERR Connection failed @ sendRoutine conn={"Logger":{}} err="pong timeout" module=p2p peer={"id":"d7113205f004797746a1ae7cbea775c11f79a8c7","ip":"65.108.136.225","port":26656}
    

    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.

  5. adizere commented on May 11, 2023

    @adizere
    ContributorAuthor

    @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 attach to gain access to stdout/err of that machine
    • identified the binary's PID and did kill -6 $PID
    • got the logs
    • looked at the stacktraces and noticed that there were tens of go routines waiting to get the app.mtx.Lock
      • among those routines was also the one that supposed to execute the block, called DeliverTxAsync;
      • this routine could not get the Lock and was stuck waiting here
      • this routine (alongside tens of others) was stuck waiting for 63 minutes at the point, indicating the deadlock
    • Sergio identified the routine that seemed to still hold the lock; that routine was still running & was part of the gRPC service for x/staking/keeper, serving a query for ValidatorDelegations.

    We informed the Osmosis team about the problem and waiting for feedback.

  6. ValarDragon commented on May 11, 2023

    @ValarDragon
    Contributor

    TY for investigating!!

    The hypothesis right now is then that:

    • Some external query happened and took a mutex
    • P2P shares the same mutex as this query
    • The external query did not terminate
    • Deadlock ensued, and peers got disconnected?

    So my understanding is that the separate ideas for us to try would be:

    • Understand why this query didn't terminate (very not clear, do we know what line it would've been?) I reviewed the FilteredPaginate code, could have been a mutex deadlock in the CacheKV store or IAVL
    • Make p2p ping/pong not share a mutex lock with queries

    ?

  7. adizere commented on May 12, 2023

    @adizere
    ContributorAuthor

    That matches my understanding, great summary!

    Deadlock ensued, and peers got disconnected?

    This is more nuanced:

    1. in the short term, peers actually don't get disconnected, the node is still able to refresh its outbound peers
    2. the problem is that consensus block processing stalls, since DeliverTxAsync requires the Lock on the same mutex that the external query is holding
    3. disconnected peers is a separate symptom, likely caused by the consensus module not being able to advance, but I am not sure; in any case, the point about disconnected peers is less severe than point (2) above

    do we know what line it would've been?

    I shared with Niccolo the full stacktrace. The relevant segment is below.

    Relevant routine from stracktrace
    goroutine 94485514 [runnable]:
    github.com/cosmos/cosmos-sdk/store/cachekv.(*memIterator).Valid(0xd861877050?)
    	<autogenerated>:1 +0x3e fp=0xd86186e1a0 sp=0xd86186e198 pc=0xe1453e
    github.com/cosmos/cosmos-sdk/store/cachekv.(*cacheMergeIterator).skipUntilExistsOrInvalid(0xd861877080)
    	github.com/cosmos/[email protected]/store/cachekv/mergeiterator.go:214 +0x4f fp=0xd86186e200 sp=0xd86186e1a0 pc=0xe11e2f
    github.com/cosmos/cosmos-sdk/store/cachekv.(*cacheMergeIterator).Key(0xd861877080)
    	github.com/cosmos/[email protected]/store/cachekv/mergeiterator.go:93 +0x25 fp=0xd86186e278 sp=0xd86186e200 pc=0xe11765
    github.com/cosmos/cosmos-sdk/store/gaskv.(*gasIterator).Key(0xd86184de60?)
    	github.com/cosmos/[email protected]/store/gaskv/store.go:153 +0x22 fp=0xd86186e290 sp=0xd86186e278 pc=0xcaebe2
    github.com/cosmos/cosmos-sdk/store/prefix.(*prefixIterator).Next(0xd86184dec0)
    	github.com/cosmos/[email protected]/store/prefix/store.go:159 +0x65 fp=0xd86186e2b8 sp=0xd86186e290 pc=0xf02745
    github.com/cosmos/cosmos-sdk/types/query.FilteredPaginate({0x2f08c80?, 0xd861876ed0?}, 0x2f0bc40?, 0xd86186e740)
    	github.com/cosmos/[email protected]/types/query/filtered_pagination.go:85 +0x256 fp=0xd86186e418 sp=0xd86186e2b8 pc=0xdc9356
    github.com/cosmos/cosmos-sdk/x/staking/keeper.Querier.ValidatorDelegations({{{0x2ed92f8, 0xc051cfd290}, {0x2f09580, 0xc001438180}, {0x2ef7fc0, 0xc00026cbd0}, {0x2f06140, 0xc000147ce0}, {0x2f0a000, 0xc000132ac8}, ...}}, ...)
    	github.com/cosmos/[email protected]/x/staking/keeper/grpc_query.go:102 +0x285 fp=0xd86186ee50 sp=0xd86186e418 pc=0x16064c5
    github.com/cosmos/cosmos-sdk/x/staking/keeper.(*Querier).ValidatorDelegations(0x272a440?, {0x2ef5098?, 0xd861876e70?}, 0x42d0eb?)
    	<autogenerated>:1 +0xc5 fp=0xd86186efc8 sp=0xd86186ee50 pc=0x1661465
    github.com/cosmos/cosmos-sdk/x/staking/types._Query_ValidatorDelegations_Handler({0x27f7a00?, 0xc0014ba0b0}, {0x2ef5098, 0xd861876e70}, 0xc02c32b450, 0x0)
    	github.com/cosmos/[email protected]/x/staking/types/query.pb.go:1822 +0x170 fp=0xd86186f020 sp=0xd86186efc8 pc=0x122de10
    github.com/cosmos/cosmos-sdk/baseapp.(*GRPCQueryRouter).RegisterService.func1({{0x2ef5028, 0xc00005c030}, {0x2f0bc40, 0xd86187c480}, {{0xb, 0xf}, {0xcf975f8271, 0x9}, 0x9215a0, {0x328fe927, ...}, ...}, ...}, ...)
    	github.com/cosmos/[email protected]/baseapp/grpcrouter.go:85 +0x1f3 fp=0xd86186f4f8 sp=0xd86186f020 pc=0xef5653
    github.com/cosmos/cosmos-sdk/baseapp.(*BaseApp).handleQueryGRPC(0xc0018abba0, 0xc052812240, {{0xd5864ca340, 0x3a, 0x3a}, {0x287f464, 0x32}, 0x9215a0, 0x0})
    	github.com/cosmos/[email protected]/baseapp/abci.go:561 +0x1af fp=0xd86186fe50 sp=0xd86186f4f8 pc=0xeee00f
    github.com/cosmos/cosmos-sdk/baseapp.(*BaseApp).Query(0xc0018abba0, {{0xd5864ca340, 0x3a, 0x3a}, {0x287f464, 0x32}, 0x9215a0, 0x0})
    	github.com/cosmos/[email protected]/baseapp/abci.go:405 +0x73d fp=0xd861870120 sp=0xd86186fe50 pc=0xeec71d
    github.com/tendermint/tendermint/abci/client.(*localClient).QuerySync(0xc247de2e40, {{0xd5864ca340, 0x3a, 0x3a}, {0x287f464, 0x32}, 0x0, 0x0})
    	github.com/tendermint/[email protected]/abci/client/local_client.go:256 +0x171 fp=0xd8618702b0 sp=0xd861870120 pc=0xfe8bf1
    github.com/tendermint/tendermint/proxy.(*appConnQuery).QuerySync(0x424ca6?, {{0xd5864ca340, 0x3a, 0x3a}, {0x287f464, 0x32}, 0x0, 0x0})
    	github.com/tendermint/[email protected]/proxy/app_conn.go:159 +0x6e fp=0xd861870300 sp=0xd8618702b0 pc=0xfec92e
    github.com/tendermint/tendermint/rpc/core.ABCIQuery(0x35322f32?, {0x287f464?, 0x3832303436342f74?}, {0xd5864ca340?, 0x455430?, 0x25fed20?}, 0x0?, 0xfe?)
    	github.com/tendermint/[email protected]/rpc/core/abci.go:20 +0xa6 fp=0xd861870398 sp=0xd861870300 pc=0x10deea6
    github.com/tendermint/tendermint/rpc/client/local.(*Local).ABCIQueryWithOptions(0x25fcf20?, {0xc662a86528?, 0x0?}, {0x287f464?, 0x0?}, {0xd5864ca340?, 0x0?, 0x0?}, {0x0, 0x0})
    	github.com/tendermint/[email protected]/rpc/client/local/local.go:87 +0x45 fp=0xd8618703e8 sp=0xd861870398 pc=0x1150705
    github.com/cosmos/cosmos-sdk/client.Context.queryABCI({{0x0, 0x0, 0x0}, {0x2f19d90, 0xcd397b5720}, {0xc07ec61140, 0x9}, {0x2efde30, 0xc00146da20}, 0x0, ...}, ...)
    	github.com/cosmos/[email protected]/client/query.go:94 +0x1ab fp=0xd861870728 sp=0xd8618703e8 pc=0xe960ab
    github.com/cosmos/cosmos-sdk/client.Context.QueryABCI(...)
    	github.com/cosmos/[email protected]/client/query.go:57
    github.com/cosmos/cosmos-sdk/client.Context.Invoke({{0x0, 0x0, 0x0}, {0x2f19d90, 0xcd397b5720}, {0xc07ec61140, 0x9}, {0x2efde30, 0xc00146da20}, 0x0, ...}, ...)
    	github.com/cosmos/[email protected]/client/grpc_query.go:86 +0x67d fp=0xd861870dc0 sp=0xd861870728 pc=0xe9543d
    github.com/cosmos/cosmos-sdk/client.(*Context).Invoke(0x7fea3d276688?, {0x2ef5098?, 0xd3d1f78de0?}, {0x287f464?, 0x0?}, {0x272a440?, 0xcd8e9bc4b0?}, {0x272a5a0?, 0xd0d4640be0?}, {0xd0d4640bc0, ...})
    	<autogenerated>:1 +0x12f fp=0xd861871158 sp=0xd861870dc0 pc=0xe9754f
    github.com/cosmos/cosmos-sdk/x/staking/types.(*queryClient).ValidatorDelegations(0xcd5dce7e40, {0x2ef5098, 0xd3d1f78de0}, 0xe?, {0xd0d4640bc0, 0x2, 0x2})
    	github.com/cosmos/[email protected]/x/staking/types/query.pb.go:1587 +0xce fp=0xd8618711d8 sp=0xd861871158 pc=0x122c72e
    github.com/cosmos/cosmos-sdk/x/staking/types.request_Query_ValidatorDelegations_0({0x2ef5098, 0xd3d1f78de0}, {0x57bd00?, 0xd87576e600?}, {0x2f0c6a0, 0xcd5dce7e40}, 0xd83dd89e00, 0x5?)
    	github.com/cosmos/[email protected]/x/staking/types/query.pb.gw.go:157 +0x256 fp=0xd861871248 sp=0xd8618711d8 pc=0x1243d36
    github.com/cosmos/cosmos-sdk/x/staking/types.RegisterQueryHandlerClient.func3({0x2ef3340, 0xcd8e9bc498}, 0xd83dd89e00, 0xc000f81980?)
    	github.com/cosmos/[email protected]/x/staking/types/query.pb.gw.go:1250 +0x16e fp=0xd861871348 sp=0xd861871248 pc=0x124bb4e
    github.com/grpc-ecosystem/grpc-gateway/runtime.(*ServeMux).ServeHTTP(0xc055d5e150, {0x2ef3340, 0xcd8e9bc498}, 0xd83dd89e00)
    	github.com/grpc-ecosystem/[email protected]/runtime/mux.go:240 +0xcd6 fp=0xd861871600 sp=0xd861871348 pc=0xdeb916
    github.com/gorilla/mux.(*Router).ServeHTTP(0xcd444eacc0, {0x2ef3340, 0xcd8e9bc498}, 0xd83dd89800)
    	github.com/gorilla/[email protected]/mux.go:210 +0x1cf fp=0xd861871728 sp=0xd861871600 pc=0xe9f26f
    github.com/gorilla/handlers.(*cors).ServeHTTP(0xcd5dcbbcb0, {0x2ef3340, 0xcd8e9bc498}, 0xd83dd89800)
    	github.com/gorilla/[email protected]/cors.go:54 +0x370 fp=0xd8618718b8 sp=0xd861871728 pc=0xe9d510
    github.com/tendermint/tendermint/rpc/jsonrpc/server.maxBytesHandler.ServeHTTP({{0x2ed1a80?, 0xcd5dcbbcb0?}, 0x42f9e7?}, {0x2ef3340?, 0xcd8e9bc498}, 0xd83dd89800)
    	github.com/tendermint/[email protected]/rpc/jsonrpc/server/http_server.go:256 +0x124 fp=0xd861871918 sp=0xd8618718b8 pc=0xeac644
    github.com/tendermint/tendermint/rpc/jsonrpc/server.(*maxBytesHandler).ServeHTTP(0x266d820?, {0x2ef3340?, 0xcd8e9bc498?}, 0xd?)
    	<autogenerated>:1 +0x4e fp=0xd861871958 sp=0xd861871918 pc=0xeb232e
    github.com/tendermint/tendermint/rpc/jsonrpc/server.RecoverAndLogHandler.func1({0x2ef39a0?, 0xd930e71960}, 0xd83dd89800)
    	github.com/tendermint/[email protected]/rpc/jsonrpc/server/http_server.go:229 +0x37f fp=0xd861871aa0 sp=0xd861871958 pc=0xeab6ff
    net/http.HandlerFunc.ServeHTTP(0xd054d7cde6?, {0x2ef39a0?, 0xd930e71960?}, 0x48df6e?)
    	net/http/server.go:2109 +0x2f fp=0xd861871ac8 sp=0xd861871aa0 pc=0x797aaf
    net/http.serverHandler.ServeHTTP({0xd3d1f789c0?}, {0x2ef39a0, 0xd930e71960}, 0xd83dd89800)
    	net/http/server.go:2947 +0x30c fp=0xd861871b78 sp=0xd861871ac8 pc=0x79b36c
    net/http.(*conn).serve(0xd62a04a1e0, {0x2ef5098, 0xcd6064a4e0})
    	net/http/server.go:1991 +0x607 fp=0xd861871fb8 sp=0xd861871b78 pc=0x796587
    net/http.(*Server).Serve.func3()
    	net/http/server.go:3102 +0x2e fp=0xd861871fe0 sp=0xd861871fb8 pc=0x79bcae
    runtime.goexit()
    	runtime/asm_amd64.s:1594 +0x1 fp=0xd861871fe8 sp=0xd861871fe0 pc=0x490141
    created by net/http.(*Server).Serve
    	net/http/server.go:3102 +0x4db

    It would be great if we can get a confirmation on the CacheKV store or IAVL deadlock.

    Make p2p ping/pong not share a mutex lock with queries

    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.

  8. added
    question
    on May 15, 2023
  9. ValarDragon commented on May 15, 2023

    @ValarDragon
    Contributor

    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
    goroutine 94485514 [runnable]:
    github.com/cosmos/cosmos-sdk/store/cachekv.(*memIterator).Valid(0xd861877050?)
    	<autogenerated>:1 +0x3e fp=0xd86186e1a0 sp=0xd86186e198 pc=0xe1453e
    github.com/cosmos/cosmos-sdk/store/cachekv.(*cacheMergeIterator).skipUntilExistsOrInvalid(0xd861877080)
    	github.com/cosmos/[email protected]/store/cachekv/mergeiterator.go:214 +0x4f fp=0xd86186e200 sp=0xd86186e1a0 pc=0xe11e2f
    github.com/cosmos/cosmos-sdk/store/cachekv.(*cacheMergeIterator).Key(0xd861877080)
    	github.com/cosmos/[email protected]/store/cachekv/mergeiterator.go:93 +0x25 fp=0xd86186e278 sp=0xd86186e200 pc=0xe11765
    github.com/cosmos/cosmos-sdk/store/gaskv.(*gasIterator).Key(0xd86184de60?)
    	github.com/cosmos/[email protected]/store/gaskv/store.go:153 +0x22 fp=0xd86186e290 sp=0xd86186e278 pc=0xcaebe2
    github.com/cosmos/cosmos-sdk/store/prefix.(*prefixIterator).Next(0xd86184dec0)
    	github.com/cosmos/[email protected]/store/prefix/store.go:159 +0x65 fp=0xd86186e2b8 sp=0xd86186e290 pc=0xf02745
    github.com/cosmos/cosmos-sdk/types/query.FilteredPaginate({0x2f08c80?, 0xd861876ed0?}, 0x2f0bc40?, 0xd86186e740)
    	github.com/cosmos/[email protected]/types/query/filtered_pagination.go:85 +0x256 fp=0xd86186e418 sp=0xd86186e2b8 pc=0xdc9356
    github.com/cosmos/cosmos-sdk/x/staking/keeper.Querier.ValidatorDelegations({{{0x2ed92f8, 0xc051cfd290}, {0x2f09580, 0xc001438180}, {0x2ef7fc0, 0xc00026cbd0}, {0x2f06140, 0xc000147ce0}, {0x2f0a000, 0xc000132ac8}, ...}}, ...)
    

    I've spent awhile looking at this, and I can't see any reason why this would deadlock. CacheKV locks:

    • There is a new CacheKV store created for every query. The CacheKV store has two locks:
      • One lock for every "direct" cacheKV operation. (Get/Set)
      • An iterator lock that gets taken when you make an iterator, and only released on iterator close.

    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

  10. ValarDragon commented on May 15, 2023

    @ValarDragon
    Contributor

    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 ValidatorDelegations query 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 this ValidatorDelegations query)

    In multiple goroutine dumps, I'm not seeing anything from store/iavl/cachekv stuck 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

  11. ValarDragon commented on May 15, 2023

    @ValarDragon
    Contributor

    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 ValidatorDelegations was running. However it was a different PID everytime. And if we count how many queries were going on, its:

    cat halt.dump | grep github.com/cosmos/[email protected]/client/grpc_query.go --count
    132
    cat halt2.dump | grep github.com/cosmos/[email protected]/client/grpc_query.go --count
    69
    cat halt3.dump | grep github.com/cosmos/[email protected]/client/grpc_query.go --count
    28
    cat now_working.dump | grep github.com/cosmos/[email protected]/client/grpc_query.go --count
    0
    

    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?

  12. sergio-mena commented on May 16, 2023

    @sergio-mena
    Collaborator

    Going to try to be careful that theres no way this query could be infinitely looping somehow

    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.

  13. ValarDragon commented on May 16, 2023

    @ValarDragon
    Contributor

    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)

  14. adizere commented on May 20, 2023

    @adizere
    ContributorAuthor

    Can confirm, its a query that can take a few hours to execute

    Great, thanks for confirming!

    How do we get queries to not be on the same lock as consensus?

    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.

  15. added
    abci
    on May 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

abcibugquestion

Type

No type

Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions