### Godot version

4.0.3

### System information

Ubuntu 22.04.2 LTS

### Issue description

If awaiting a signal, and there are unfreed objects in memory, and the user closes the game, then the executable crashes with this error:
```
ERROR: Condition "_first != nullptr" is true.
   at: ~List (./core/templates/self_list.h:106)
```
In a build (rather than running from the editor), this is followed by this error:
```
WARNING: ObjectDB instances leaked at exit (run with --verbose for details).
     at: cleanup (core/object/object.cpp:1982)
ERROR: Resources still in use at exit (run with --verbose for details).
   at: clear (core/io/resource.cpp:489)
```

This happens whether the object in question is an `Object` subclass that has not been freed or a `RefCounted`. 

What I expect to happen is that the application should close without throwing these errors. I expect any such memory to be automatically freed on application exit, or at least for the application to close gracefully, without throwing an error. The application's giving an error code produces a bad user experience that I cannot avoid if using signals and non-Node scripts.

I have seen the same behavior on Windows 10, although I am writing this report from Linux.

Note that these errors show up in the terminal that launched Godot (the engine or the built game), not within Godot's "Output" window.

### Steps to reproduce

Please see the attached minimal reproduction project. Run `main.tscn` and close the running application: it will produce an error. Run the application again and click the button, whose `pressed` signal is being awaited in the script. Now close the application, and no error will be produced.

The error is easiest to see if godot itself was started from the command-line: this error is reported in the terminal that launched Godot, not within Godot's built-in terminal.

Whether the allocated object is an unfreed `Object` or a `RefCounted` does not seem to matter. The example project uses `item.gd` as a minimal `RefCounted`. Once can change it to an `Object` and stick an `_item.free()` at the end of the `_ready()` function, and the same behavior will occur.

To make your own reproduction:
- Make a custom `Object` or `RefCounted` script
- In the main scene, e.g. in `_ready`, create an instance, then await a signal
- Run the application and close it before that signal is received.

Here is a sample. Given a script like this:
```
class_name Item
extends RefCounted
```
Then the following scene will generate the problem if closed before clicking a button in it:
```
extends Control

func _ready():
	var _item := Item.new()
	await $Button.pressed
```

### Minimal reproduction project

[repro_await.zip](https://github.com/godotengine/godot/files/11722690/repro_await.zip)

int current = 0;
#ifdef DEBUG_ENABLED
	MutexLock lock(this->mutex);
	SelfList<GDScriptFunction> *elem = function_list.first();
	while (elem) {
		if (current >= p_info_max) {
			break;
		}
		if (elem->self()->profile.last_frame_call_count > 0) {
			p_info_arr[current].call_count = elem->self()->profile.last_frame_call_count;
			p_info_arr[current].self_time = elem->self()->profile.last_frame_self_time;
			p_info_arr[current].total_time = elem->self()->profile.last_frame_total_time;
			p_info_arr[current].signature = elem->self()->profile.signature;
			current++;
		}
		elem = elem->next();
	}
#endif
	return current;
}
struct GDScriptDepSort {
	
	bool operator()(const Ref<GDScript> &A, const Ref<GDScript> &B) const {