1
0
mirror of https://github.com/emilk/egui.git synced 2026-09-01 14:20:04 -04:00

Fix deadlock in ImageLoader, FileLoader, EhttpLoader (#7494)

* Recently CI runs started to hang randomly:
https://github.com/emilk/egui/actions/runs/17427449210/job/49477714447?pr=7359

This fixes the deadlock and adds the basic deadlock detection we also
added to Mutexes in #7468.

Also, interestingly, the more sophisticated deadlock detection (behind
the deadlock_detection feature) didn't catch this for some reason. I
wonder why it exists in the first place, when parking_lot also has built
in deadlock detection? It also seems to make tests slower, widget_tests
usually needs ~30s, with the deadlock detection removed its only ~12s.
This commit is contained in:
Lucas Meurer
2025-09-04 10:31:26 +02:00
committed by GitHub
parent d3cd6d44cf
commit fa4bee3bf7
4 changed files with 80 additions and 28 deletions

View File

@@ -95,14 +95,23 @@ impl BytesLoader for FileLoader {
}
Err(err) => Err(err.to_string()),
};
let mut cache = cache.lock();
if let std::collections::hash_map::Entry::Occupied(mut entry) = cache.entry(uri.clone()) {
let entry = entry.get_mut();
*entry = Poll::Ready(result);
let repaint = {
let mut cache = cache.lock();
if let std::collections::hash_map::Entry::Occupied(mut entry) = cache.entry(uri.clone()) {
let entry = entry.get_mut();
*entry = Poll::Ready(result);
ctx.request_repaint();
log::trace!("Finished loading {uri:?}");
true
} else {
log::trace!("Canceled loading {uri:?}\nNote: This can happen if `forget_image` is called while the image is still loading.");
false
}
};
// We may not lock Context while the cache lock is held (see ImageLoader::load
// for details).
if repaint {
ctx.request_repaint();
log::trace!("Finished loading {uri:?}");
} else {
log::trace!("Canceled loading {uri:?}\nNote: This can happen if `forget_image` is called while the image is still loading.");
}
}
})