### Godot version

4.2.beta5, `master` (e38686f85b768a451dc06324fe2471adc8665448)

### System information

Mageia 9 - Vulkan (Forward+) - dedicated AMD Radeon RX Vega M GL Graphics (RADV VEGAM) () - Intel(R) Core(TM) i7-8705G CPU @ 3.10GHz (8 Threads)

### Issue description

I noticed a deadlock in `GDScriptCache::get_full_script` when trying to open GDQuest's 3D TPS demo in 4.2 beta 5 and latest `master` (e38686f85b768a451dc06324fe2471adc8665448). I haven't yet tested earlier versions to see whether I can pinpoint a regression time, I'll do that next.

It happens when opening the project in Godot 4.2 *after* having opened it once in 4.1.3, ensuring that all files in `.godot` have been generated by 4.1.3.

The editor freezes, and attaching a debugger gives me this stacktrace of where it seems to be stuck, on a mutex in `GDScriptCache::get_full_script`:

```
(gdb) bt
#0  0x00007f4c8e85d97c in __lll_lock_wait () from /lib64/libc.so.6
#1  0x00007f4c8e86361f in pthread_mutex_lock@@GLIBC_2.2.5 () from /lib64/libc.so.6
#2  0x00000000056d59b7 in __gthread_mutex_lock (__mutex=0xbae97e8) at /usr/include/c++/12/x86_64-mageia-linux/bits/gthr-default.h:749
#3  0x00000000056d5a07 in __gthread_recursive_mutex_lock (__mutex=0xbae97e8) at /usr/include/c++/12/x86_64-mageia-linux/bits/gthr-default.h:811
#4  0x00000000056d5a3c in std::recursive_mutex::lock (this=0xbae97e8) at /usr/include/c++/12/mutex:108
#5  0x00000000056d6309 in std::unique_lock<std::recursive_mutex>::lock (this=0x7fff39a697a0) at /usr/include/c++/12/bits/unique_lock.h:139
#6  0x00000000056d61d7 in std::unique_lock<std::recursive_mutex>::unique_lock (this=0x7fff39a697a0, __m=...) at /usr/include/c++/12/bits/unique_lock.h:69
#7  0x0000000005f9324a in MutexLock<MutexImpl<std::recursive_mutex> >::MutexLock (p_mutex=..., this=<optimized out>) at ./core/os/mutex.h:122
#8  GDScriptCache::get_full_script (p_path=..., r_error=@0x7fff39a6982c: OK, p_owner=..., p_update_from_disk=false) at ./modules/gdscript/gdscript_cache.cpp:273
#9  0x0000000005f66dcf in ResourceFormatLoaderGDScript::load (this=0xbec68f0, p_path=..., p_original_path=..., r_error=0x221a1d6c, p_use_sub_threads=false, r_progress=0x221a1d60, 
    p_cache_mode=ResourceFormatLoader::CACHE_MODE_REUSE) at ./modules/gdscript/gdscript.cpp:2699
#10 0x00000000099e4b2d in ResourceLoader::_load (p_path=..., p_original_path=..., p_type_hint=..., p_cache_mode=ResourceFormatLoader::CACHE_MODE_REUSE, r_error=0x221a1d6c, p_use_sub_threads=false, r_progress=0x221a1d60)
    at ./core/io/resource_loader.cpp:261
#11 0x00000000099e524c in ResourceLoader::_thread_load_function (p_userdata=0x221a1d18) at ./core/io/resource_loader.cpp:319
#12 0x00000000099e5e91 in ResourceLoader::_load_start (p_path=..., p_type_hint=..., p_thread_mode=ResourceLoader::LOAD_THREAD_FROM_CURRENT, p_cache_mode=ResourceFormatLoader::CACHE_MODE_REUSE)
    at ./core/io/resource_loader.cpp:498
#13 0x00000000088c7ea5 in ResourceLoaderText::load (this=0x7fff39a6a560) at ./scene/resources/resource_format_text.cpp:467
#14 0x00000000088d3afd in ResourceFormatLoaderText::load (this=0xd591dd0, p_path=..., p_original_path=..., r_error=0x229f462c, p_use_sub_threads=false, r_progress=0x229f4620, 
    p_cache_mode=ResourceFormatLoader::CACHE_MODE_REUSE) at ./scene/resources/resource_format_text.cpp:1651
#15 0x00000000099e4b2d in ResourceLoader::_load (p_path=..., p_original_path=..., p_type_hint=..., p_cache_mode=ResourceFormatLoader::CACHE_MODE_REUSE, r_error=0x229f462c, p_use_sub_threads=false, r_progress=0x229f4620)
    at ./core/io/resource_loader.cpp:261
#16 0x00000000099e524c in ResourceLoader::_thread_load_function (p_userdata=0x229f45d8) at ./core/io/resource_loader.cpp:319
#17 0x00000000099e5e91 in ResourceLoader::_load_start (p_path=..., p_type_hint=..., p_thread_mode=ResourceLoader::LOAD_THREAD_FROM_CURRENT, p_cache_mode=ResourceFormatLoader::CACHE_MODE_REUSE)
    at ./core/io/resource_loader.cpp:498
#18 0x00000000088c7ea5 in ResourceLoaderText::load (this=0x7fff39a6d430) at ./scene/resources/resource_format_text.cpp:467
#19 0x00000000088d3afd in ResourceFormatLoaderText::load (this=0xd591dd0, p_path=..., p_original_path=..., r_error=0x23cdc08c, p_use_sub_threads=false, r_progress=0x23cdc080, 
    p_cache_mode=ResourceFormatLoader::CACHE_MODE_REPLACE) at ./scene/resources/resource_format_text.cpp:1651
#20 0x00000000099e4b2d in ResourceLoader::_load (p_path=..., p_original_path=..., p_type_hint=..., p_cache_mode=ResourceFormatLoader::CACHE_MODE_REPLACE, r_error=0x23cdc08c, p_use_sub_threads=false, r_progress=0x23cdc080)
    at ./core/io/resource_loader.cpp:261
--Type <RET> for more, q to quit, c to continue without paging--
#21 0x00000000099e524c in ResourceLoader::_thread_load_function (p_userdata=0x23cdc038) at ./core/io/resource_loader.cpp:319
#22 0x00000000099e5e91 in ResourceLoader::_load_start (p_path=..., p_type_hint=..., p_thread_mode=ResourceLoader::LOAD_THREAD_FROM_CURRENT, p_cache_mode=ResourceFormatLoader::CACHE_MODE_REPLACE)
    at ./core/io/resource_loader.cpp:498
#23 0x00000000099e5989 in ResourceLoader::load (p_path=..., p_type_hint=..., p_cache_mode=ResourceFormatLoader::CACHE_MODE_REPLACE, r_error=0x7fff39a6fae4) at ./core/io/resource_loader.cpp:415
#24 0x0000000007105359 in EditorNode::load_scene (this=0xe0d48a0, p_scene=..., p_ignore_broken_deps=false, p_set_inherited=false, p_clear_errors=true, p_force_open_imported=false, p_silent_change_tab=false)
    at ./editor/editor_node.cpp:3760
#25 0x0000000007111e3e in EditorNode::_load_open_scenes_from_config (this=0xe0d48a0, p_layout=...) at ./editor/editor_node.cpp:5466
#26 0x000000000710ee30 in EditorNode::_load_editor_layout (this=0xe0d48a0) at ./editor/editor_node.cpp:5090
#27 0x00000000070f05e0 in EditorNode::_sources_changed (this=0xe0d48a0, p_exist=false) at ./editor/editor_node.cpp:1049
#28 0x0000000007304085 in call_with_variant_args_helper<EditorNode, bool, 0ul> (p_instance=0xe0d48a0, p_method=(void (EditorNode::*)(EditorNode * const, bool)) 0x70f0526 <EditorNode::_sources_changed(bool)>, 
    p_args=0x7fff39a70480, r_error=...) at ./core/variant/binder_common.h:303
#29 0x00000000072f5101 in call_with_variant_args<EditorNode, bool> (p_instance=0xe0d48a0, p_method=(void (EditorNode::*)(EditorNode * const, bool)) 0x70f0526 <EditorNode::_sources_changed(bool)>, p_args=0x7fff39a70480, 
    p_argcount=1, r_error=...) at ./core/variant/binder_common.h:417
#30 0x00000000072e2542 in CallableCustomMethodPointer<EditorNode, bool>::call (this=0x1cf69270, p_arguments=0x7fff39a70480, p_argcount=1, r_return_value=..., r_call_error=...) at ./core/object/callable_method_pointer.h:104
#31 0x0000000009afe4e5 in Callable::callp (this=0x21f90c50, p_arguments=0x7fff39a70480, p_argcount=1, r_return_value=..., r_call_error=...) at ./core/variant/callable.cpp:57
#32 0x0000000009e112cc in Object::emit_signalp (this=0xe12b6a0, p_name=..., p_args=0x7fff39a70480, p_argcount=1) at ./core/object/object.cpp:1127
#33 0x0000000007dbc970 in Node::emit_signalp (this=0xe12b6a0, p_name=..., p_args=0x7fff39a70480, p_argcount=1) at ./scene/main/node.cpp:3606
#34 0x000000000659371c in Object::emit_signal<bool> (this=0xe12b6a0, p_name=...) at ./core/object/object.h:922
#35 0x0000000006f4f85b in EditorFileSystem::_notification (this=0xe12b6a0, p_what=17) at ./editor/editor_file_system.cpp:1285
#36 0x0000000006fe5178 in EditorFileSystem::_notificationv (this=0xe12b6a0, p_notification=17, p_reversed=false) at ./editor/editor_file_system.h:146
#37 0x0000000009e0f812 in Object::notification (this=0xe12b6a0, p_notification=17, p_reversed=false) at ./core/object/object.cpp:837
#38 0x0000000007dc1db0 in SceneTree::_process_group (this=0xe065140, p_group=0xe065398, p_physics=false) at ./scene/main/scene_tree.cpp:951
#39 0x0000000007dc2329 in SceneTree::_process (this=0xe065140, p_physics=false) at ./scene/main/scene_tree.cpp:1028
#40 0x0000000007dc0268 in SceneTree::process (this=0xe065140, p_time=0.077858000000000122) at ./scene/main/scene_tree.cpp:508
#41 0x0000000005754650 in Main::iteration () at main/main.cpp:3636
#42 0x00000000056cddce in OS_LinuxBSD::run (this=0x7fff39a70960) at platform/linuxbsd/os_linuxbsd.cpp:933
#43 0x00000000056c6840 in main (argc=2, argv=0x7fff39a70f48) at platform/linuxbsd/godot_linuxbsd.cpp:74
```

### Steps to reproduce

**Edit:** See below, at least one of the two Godot versions must be self-contained to reproduce the issue.

- Check out https://github.com/gdquest-demos/godot-4-3d-third-person-controller (commit b4298d4b524a2dfb05daa58c88867980f0ddc83b at the time of writing).
- Ensure `.godot` is deleted, also remove the Godot cache for good measure (`~/.cache/godot/` or similar locations) - that last part may not be needed but I haven't tested without that step.
- Open the project in Godot 4.1.3, letting it import everything. Close the editor.
- Open the project in latest Godot 4.2 - it should deadlock.
- If you want to repeat the test, make sure to `git checkout` any changes made by Godot 4.2, clean `.godot`, etc.

### Minimal reproduction project

Not really minimal, I haven't yet tried to narrow it down.
But the stacktrace suggests an issue with GDScript, possibly preloading or cyclic references.
if (err != OK) {
			EditorNode::get_singleton()->add_io_error(TTR("Cannot remove:") + "\n" + remap_path + "\n");
		}
	}
	EditorSettings::get_singleton()->set_project_metadata("surface_upgrade_tool", "reimport_paths", Vector<String>());
	emit_signal(SNAME("upgrade_finished"));
}
void SurfaceUpgradeTool::_bind_methods() {
	ADD_SIGNAL(MethodInfo("upgrade_finished"));
}
SurfaceUpgradeTool::SurfaceUpgradeTool() {
	singleton = this;
	RS::get_singleton()->set_surface_upgrade_callback(_try_show_popup);
}
SurfaceUpgradeTool::~SurfaceUpgradeTool() {}
void SurfaceUpgradeDialog::_notification(int p_what) {
	switch (p_what) {
		case NOTIFICATION_READY:
			
			connect("confirmed", callable_mp(SurfaceUpgradeTool::get_singleton(), &SurfaceUpgradeTool::prepare_upgrade));
			break;
	}
}
SurfaceUpgradeDialog::SurfaceUpgradeDialog() {
	const String confirmation_message = TTR("The mesh format has changed in Godot 4.2, which affects both imported meshes and meshes authored inside of Godot. The engine needs to update the format in order to use those meshes.\n\nIf your project predates Godot 4.2 and contains meshes we recommend you run this one time conversion tool. This update will restart the editor and may take several minutes. Upgrading will make the meshes incompatible with previous versions of Godot.\n\nYou can still use your existing meshes as is. The engine will update each mesh in memory, but the update will not be saved. Choosing this option will lead to slower load times every time this project is loaded.");
	set_text(confirmation_message);
	set_autowrap(true);
	get_label()->set_custom_minimum_size(Size2(750 * EDSCALE, 0));
}