daemon|util: Don't remove from list while iterating (#11208)

* daemon: Iterate over a copy of `websockets`

Currently when it fails to send the response to one websocket it skips 
the next websocket in list becaue we remove from the list while 
iterating.

* util: Iterate over a copy of `peers_with_peak`

Currently when a peer is closed it skips the check for the next peer in 
the list becaue we remove from the list while iterating.
This commit is contained in:
dustinface 2022-04-22 19:55:57 +02:00 committed by GitHub
parent f9c4f1f96d
commit c0f3d4d231
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 3 deletions

View File

@ -613,7 +613,7 @@ class WebSocketServer:
response = create_payload("keyring_status_changed", keyring_status, "daemon", destination)
for websocket in websockets:
for websocket in websockets.copy():
try:
await websocket.send_str(response)
except Exception as e:
@ -672,7 +672,7 @@ class WebSocketServer:
response = create_payload("state_changed", message, service, "wallet_ui")
for websocket in websockets:
for websocket in websockets.copy():
try:
await websocket.send_str(response)
except Exception as e:

View File

@ -15,7 +15,7 @@ async def check_fork_next_block(
potential_peek = uint32(our_peak_height + 1)
# This is the fork point in SES in the case where no fork was detected
if blockchain.get_peak_height() is not None and fork_point_height == max_fork_ses_height:
for peer in peers_with_peak:
for peer in peers_with_peak.copy():
if peer.closed:
peers_with_peak.remove(peer)
continue