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,11 +613,17 @@ impl LightProtocol {
trace!(target: "les", "Peer {} disconnecting", 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) {
None => return,
Some(peer_info) => {
let peer_info = peer_info.into_inner();
let mut unfulfilled: Vec<_> = peer_info.pending_requests.collect_ids();
unfulfilled.extend(peer_info.failed_requests);
unfulfilled
}
};
for handler in &self.handlers {
handler.on_disconnect(&Ctx {
peer: peer,
@ -626,7 +632,6 @@ impl LightProtocol {
}, &unfulfilled)
}
}
}
/// Execute the given closure with a basic context derived from the I/O context.
pub fn with_context<F, T>(&self, io: &IoContext, f: F) -> T