From e72b9625d7a2a55f940deeb31d71b41122371a83 Mon Sep 17 00:00:00 2001 From: robtfm <50659922+robtfm@users.noreply.github.com> Date: Fri, 4 Oct 2024 13:28:57 +0100 Subject: [PATCH] drop info locks in single threaded (#15522) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Objective addresses half of issue #15508 avoid asset server deadlock when `multi_threaded` feature is not enabled. ## Solution drop the locks in the single-threaded case. the lock is still held with the `multi-threaded` feature enabled to avoid re-locking to insert the load task. i guess this might possibly cause issues on single-core machines ... is that something we should worry about? --------- Co-authored-by: Christian Hughes <9044780+ItsDoot@users.noreply.github.com> Co-authored-by: james7132 Co-authored-by: Chris Russell <8494645+chescock@users.noreply.github.com> Co-authored-by: Emerson Coskey <56370779+ecoskey@users.noreply.github.com> Co-authored-by: Alice Cecile Co-authored-by: Tim Co-authored-by: Joona Aalto Co-authored-by: s-puig <39652109+s-puig@users.noreply.github.com> Co-authored-by: Carter Anderson Co-authored-by: Liam Gallagher Co-authored-by: Matty Co-authored-by: Zachary Harrold Co-authored-by: Benjamin Brienen Co-authored-by: charlotte Co-authored-by: akimakinai <105044389+akimakinai@users.noreply.github.com> Co-authored-by: Antony Co-authored-by: JohnTheCoolingFan <43478602+JohnTheCoolingFan@users.noreply.github.com> Co-authored-by: hshrimp <182684536+hooded-shrimp@users.noreply.github.com> Co-authored-by: Gino Valente <49806985+MrGVSV@users.noreply.github.com> Co-authored-by: Dokkae <90514461+Dokkae6949@users.noreply.github.com> Co-authored-by: François Mockers Co-authored-by: MiniaczQ Co-authored-by: Pablo Reinhardt <126117294+pablo-lua@users.noreply.github.com> Co-authored-by: JMS55 <47158642+JMS55@users.noreply.github.com> Co-authored-by: Sou1gh0st Co-authored-by: Robert Walter <26892280+RobWalt@users.noreply.github.com> Co-authored-by: eckz <567737+eckz@users.noreply.github.com> Co-authored-by: Matty <2975848+mweatherley@users.noreply.github.com> Co-authored-by: IQuick 143 Co-authored-by: Giacomo Stevanato Co-authored-by: Clar Fon <15850505+clarfonthey@users.noreply.github.com> Co-authored-by: andriyDev Co-authored-by: TheBigCheese <32036861+13ros27@users.noreply.github.com> Co-authored-by: Kristoffer Søholm Co-authored-by: IceSentry Co-authored-by: Josh Robson Chase Co-authored-by: Erik Živković Co-authored-by: ChosenName <69129796+ChosenName@users.noreply.github.com> Co-authored-by: mgi388 <135186256+mgi388@users.noreply.github.com> Co-authored-by: SpecificProtagonist Co-authored-by: ickshonpe Co-authored-by: Gabriel Bourgeois Co-authored-by: UkoeHB <37489173+UkoeHB@users.noreply.github.com> Co-authored-by: Trashtalk217 Co-authored-by: re0312 Co-authored-by: re0312 <45868716+re0312@users.noreply.github.com> Co-authored-by: Periwink Co-authored-by: Anselmo Sampietro Co-authored-by: rudderbucky Co-authored-by: aecsocket <43144841+aecsocket@users.noreply.github.com> Co-authored-by: Andreas <34456840+nilsiker@users.noreply.github.com> Co-authored-by: Ludwig DUBOS Co-authored-by: Ensar Sarajčić Co-authored-by: Kanabenki Co-authored-by: François Mockers Co-authored-by: m-edlund Co-authored-by: vero Co-authored-by: Hennadii Chernyshchyk Co-authored-by: Litttle_fish <38809254+Litttlefish@users.noreply.github.com> Co-authored-by: BD103 <59022059+BD103@users.noreply.github.com> Co-authored-by: Rich Churcher Co-authored-by: Viktor Gustavsson Co-authored-by: Dragoș Tiselice Co-authored-by: Miles Silberling-Cook Co-authored-by: notmd <33456881+notmd@users.noreply.github.com> Co-authored-by: Matt Tracy Co-authored-by: Patrick Walton Co-authored-by: SpecificProtagonist Co-authored-by: rewin Co-authored-by: a.yamaev Co-authored-by: fluffiac --- crates/bevy_asset/src/server/mod.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/crates/bevy_asset/src/server/mod.rs b/crates/bevy_asset/src/server/mod.rs index 316642a45a..a56e653818 100644 --- a/crates/bevy_asset/src/server/mod.rs +++ b/crates/bevy_asset/src/server/mod.rs @@ -420,6 +420,10 @@ impl AssetServer { infos: &mut AssetInfos, guard: G, ) { + // drop the lock on `AssetInfos` before spawning a task that may block on it in single-threaded + #[cfg(any(target_arch = "wasm32", not(feature = "multi_threaded")))] + drop(infos); + let owned_handle = handle.clone(); let server = self.clone(); let task = IoTaskPool::get().spawn(async move { @@ -469,6 +473,11 @@ impl AssetServer { HandleLoadingMode::Request, meta_transform, ); + + // drop the lock on `AssetInfos` before spawning a task that may block on it in single-threaded + #[cfg(any(target_arch = "wasm32", not(feature = "multi_threaded")))] + drop(infos); + if !should_load { return handle; } @@ -778,6 +787,11 @@ impl AssetServer { let mut infos = self.data.infos.write(); let handle = infos.create_loading_handle_untyped(TypeId::of::(), core::any::type_name::()); + + // drop the lock on `AssetInfos` before spawning a task that may block on it in single-threaded + #[cfg(any(target_arch = "wasm32", not(feature = "multi_threaded")))] + drop(infos); + let id = handle.id(); let event_sender = self.data.asset_event_sender.clone();