Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Thread can deadlock when using a worker thread to load a C# script with a generic base class #99839

Open
preslavnpetrov opened this issue Nov 29, 2024 · 0 comments · May be fixed by #99539
Open

Comments

@preslavnpetrov
Copy link
Contributor

Tested versions

  • Reproducible in: 4.4dev5

System information

Godot v4.4.dev5.mono - Windows 10.0.26100 - Multi-window, 1 monitor - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 2070 Super with Max-Q Design (NVIDIA; 31.0.15.4633) - Intel(R) Core(TM) i7-10875H CPU @ 2.30GHz (16 threads)

Issue description

Currently, if we use either a worker thread with ResourceLoader::load() or use ResourceLoader::load_threaded_request(), and try to load any resource with a dependency on a script that inherits a generic C# class, we run into a _scriptTypeBiMap.ReadWriteLock deadlock.

This happens in a very specific circumstance:

  1. The script and its base hasn't been loaded before, so it's not populated into the BiMap
  2. Calling the load from a worker thread will make the ResourceLoader::load() call from inside godot_sharp_internal_script_load to spin up a separate worker thread to load the dependency base script
  3. This secondary worker thread will try to get the script from the BiMap unsuccessfully, since it hasn't been populated yet, and will then fall back to creating the script bridge. While doing so, it will try to lock the already locked BiMap ReadWriteLock from when we were loading it's child script

Steps to reproduce

  1. Download the MRP
  2. Launch the project with a build of Godot4.4dev5 with the --verbose arg
  3. Click the Attempt Repro button several times while looking at the log.
  4. Eventually you should see the load stall at the first generic csharp:// script and not manage to print "Loaded successfully"

Minimal reproduction project (MRP)

thread-lock-mrp.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants