chia-blockchain: [Bug] Stale peers can't be removed

What happened?

If a peer has not connected in a long time, “chia show -r peer_id” does not remove it.

Example:

FULL_NODE <removed>                          40698/8444  23cf14b6... Nov 06 15:45:25     13.7|1.2    
                                                 -SB Height:  1104692    -Hash: 9476b861...
FULL_NODE <removed>                          43361/8444  4528e678... Nov 06 11:09:24      0.2|0.0    
                                                 -SB Height:   644118    -Hash: 759b23eb...

First node is shown for reference of current height and time. Second node is far behind and last contact was more than 4 hours ago.

If I then execute “chia show -r 4528e678”, that peer is not removed from the table. With INFO level logging, nothing is recorded in the log. If I execute a remove via RPC call, the return is {“success”: true} however, the peer is still not removed.

Version

1.2.11

What platform are you using?

Linux

What ui mode are you using?

CLI

Relevant log output

N/A

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 2
  • Comments: 22 (6 by maintainers)

Most upvoted comments

There is a race condition. The ChiaServer class is creating a WSChiaConnection passing self.connection_closed callback to its init method. Then it calls self.connection_added(connection, ...) adding connection to the list of peers. Connection may have been closed in between and thus it is leaving an already closed connection in the list.

The WSChiaConnection.close method only calls close_callback once.

https://github.com/Chia-Network/chia-blockchain/blob/659f4f489081939387d6704b77c4477edb278ae1/chia/server/ws_connection.py#L195-L196

this is causing the issue described. Even if you try to manually disconnect it, the close method won’t call close_callback and the connection will remain in the list.

If you want to get rid of the stale nodes, there is a counter-intuitive workaround: just manually add the stale node again and it will get removed. chia show -a <IP address of the stale node>:8444

I believe this is fixed in #13727 and should be included with 1.7.0 when released.

Any chance we can get this fixed in the upcoming release if it’s a simple fix? https://github.com/Chia-Network/chia-blockchain/issues/9172#issuecomment-1000281772 seems to have indentified the issue.