AleoNet / snarkOS

A Decentralized Operating System for ZK Applications
http://snarkos.org
Apache License 2.0
4.07k stars 2.57k forks source link

[Bug] Memory leak in seen_outbound_block_requests #3326

Open elderhammer opened 1 week ago

elderhammer commented 1 week ago

🐛 Bug Report

seen_outbound_block_requests may contain some old requests and never be cleaned up.

2024-06-23T15:27:56.042427Z DEBUG snarkos_node_router::helpers::cache: Block requests: {127.0.0.1:4132: {BlockRequest { start_height: 3517, end_height: 3518 }}, 127.0.0.1:42031: {}, 127.0.0.1:4203: {BlockRequest { start_height: 211, end_height: 216 }, BlockRequest { start_height: 21, end_height: 26 }, BlockRequest { start_height: 41, end_height: 46 }, BlockRequest { start_height: 61, end_height: 66 }, BlockRequest { start_height: 11, end_height: 16 }, BlockRequest { start_height: 121, end_height: 126 }, BlockRequest { start_height: 181, end_height: 186 }, BlockRequest { start_height: 186, end_height: 191 }, BlockRequest { start_height: 1, end_height: 6 }, BlockRequest { start_height: 116, end_height: 121 }, BlockRequest { start_height: 101, end_height: 106 }, BlockRequest { start_height: 126, end_height: 131 }, BlockRequest { start_height: 196, end_height: 201 }, BlockRequest { start_height: 216, end_height: 221 }, BlockRequest { start_height: 146, end_height: 151 }, BlockRequest { start_height: 26, end_height: 31 }, BlockRequest { start_height: 36, end_height: 41 }, BlockRequest { start_height: 221, end_height: 226 }, BlockRequest { start_height: 16, end_height: 21 }, BlockRequest { start_height: 96, end_height: 101 }, BlockRequest { start_height: 66, end_height: 71 }, BlockRequest { start_height: 111, end_height: 116 }, BlockRequest { start_height: 51, end_height: 56 }, BlockRequest { start_height: 136, end_height: 141 }, BlockRequest { start_height: 206, end_height: 211 }, BlockRequest { start_height: 226, end_height: 231 }, BlockRequest { start_height: 71, end_height: 76 }}}
...
2024-06-23T15:58:41.527649Z DEBUG snarkos_node_router::helpers::cache: Block requests: {127.0.0.1:42031: {}, 127.0.0.1:4201: {}, 127.0.0.1:4132: {BlockRequest { start_height: 10434, end_height: 10435 }}, 127.0.0.1:4203: {BlockRequest { start_height: 211, end_height: 216 }, BlockRequest { start_height: 21, end_height: 26 }, BlockRequest { start_height: 41, end_height: 46 }, BlockRequest { start_height: 61, end_height: 66 }, BlockRequest { start_height: 11, end_height: 16 }, BlockRequest { start_height: 121, end_height: 126 }, BlockRequest { start_height: 181, end_height: 186 }, BlockRequest { start_height: 186, end_height: 191 }, BlockRequest { start_height: 1, end_height: 6 }, BlockRequest { start_height: 116, end_height: 121 }, BlockRequest { start_height: 101, end_height: 106 }, BlockRequest { start_height: 126, end_height: 131 }, BlockRequest { start_height: 196, end_height: 201 }, BlockRequest { start_height: 216, end_height: 221 }, BlockRequest { start_height: 146, end_height: 151 }, BlockRequest { start_height: 26, end_height: 31 }, BlockRequest { start_height: 36, end_height: 41 }, BlockRequest { start_height: 221, end_height: 226 }, BlockRequest { start_height: 16, end_height: 21 }, BlockRequest { start_height: 96, end_height: 101 }, BlockRequest { start_height: 66, end_height: 71 }, BlockRequest { start_height: 111, end_height: 116 }, BlockRequest { start_height: 51, end_height: 56 }, BlockRequest { start_height: 136, end_height: 141 }, BlockRequest { start_height: 206, end_height: 211 }, BlockRequest { start_height: 226, end_height: 231 }, BlockRequest { start_height: 71, end_height: 76 }}}

Steps to Reproduce

  1. When sending a block request to a peer, the block request will be recorded https://github.com/AleoNet/snarkOS/blob/09aa62b4b877c5e96689ba2e0c77d5fd1c69ae7c/node/router/src/outbound.rs#L60-L63
  2. The peer closes the connection
  3. Since no block response will be received, the block request will not be cleaned up https://github.com/AleoNet/snarkOS/blob/09aa62b4b877c5e96689ba2e0c77d5fd1c69ae7c/node/router/src/inbound.rs#L111-L114

Expected Behavior

This shouldn't happen.

Your Environment

snarkOS Version: 5d4de0286964a72ecd2b0c4ace30a938ef269086