ensure write lock isn't held when calling handlers (#4285)

This commit is contained in:
Robert Habermeier 2017-01-24 20:15:59 +01:00 committed by Gav Wood
parent 73b67da3cf
commit b739704902

View File

@ -613,18 +613,23 @@ impl LightProtocol {
trace!(target: "les", "Peer {} disconnecting", peer); trace!(target: "les", "Peer {} disconnecting", peer);
self.pending_peers.write().remove(&peer); self.pending_peers.write().remove(&peer);
if let Some(peer_info) = self.peers.write().remove(&peer) { let unfulfilled = match self.peers.write().remove(&peer) {
let peer_info = peer_info.into_inner(); None => return,
let mut unfulfilled: Vec<_> = peer_info.pending_requests.collect_ids(); Some(peer_info) => {
unfulfilled.extend(peer_info.failed_requests); let peer_info = peer_info.into_inner();
let mut unfulfilled: Vec<_> = peer_info.pending_requests.collect_ids();
unfulfilled.extend(peer_info.failed_requests);
for handler in &self.handlers { unfulfilled
handler.on_disconnect(&Ctx {
peer: peer,
io: io,
proto: self,
}, &unfulfilled)
} }
};
for handler in &self.handlers {
handler.on_disconnect(&Ctx {
peer: peer,
io: io,
proto: self,
}, &unfulfilled)
} }
} }