Repository: godot
Issue: Export randomly fails on vanilla environments with "Scan thread aborted"
Labels: bug,topic:editor,needs testing,topic:export

### Godot version

3.5-rc8

### System information

Ubuntu Latest (Ubuntu 22.04 LTS) in Docker

### Issue description

I'm exporting a project for Windows & Linux in a Github Action. When exporting a project in Github Actions environment, builds randomly fail (around 20% of the time) which makes it look like there's an internal race condition happening. Also the binary exits with code 0 for some reason, even though the export has failed.
Sometimes both exports fail (Win & Linux), sometimes one of them, and sometimes both succeed.
Here's the log of a failed build (notice the `Scan thread aborted...` warning):

```
ERROR: Failed loading resource: res://.import/icon.png-dff180777d78a0c53a9d6180af049eb9.stex. Make sure resources have been imported by opening the project in the editor at least once.
   at: _load (core/io/resource_loader.cpp:270)
ERROR: Expected Image data size of 256x256x2 (without mipmaps) = 131072 bytes, got 174762 bytes instead.

WARNING: Scan thread aborted...           <<--------------------------------------------
     at: _notification (editor/editor_file_system.cpp:1087)
ERROR: Condition "_first != nullptr" is true.
   at: ~List (./core/self_list.h:108)
ERROR: Condition "_first != nullptr" is true.
   at: ~List (./core/self_list.h:108)
WARNING: ObjectDB instances leaked at exit (run with --verbose for details).
     at: cleanup (core/object.cpp:2070)
ERROR: Resources still in use at exit (run with --verbose for details).
[exited with code 0]
```

At other times, instead of this error, I can see the following output as the build is successfully produced:

```
ERROR: Failed loading resource: res://.import/icon.png-dff180777d78a0c53a9d6180af049eb9.stex. Make sure resources have been imported by opening the project in the editor at least once.
   at: _load (core/io/resource_loader.cpp:270)
ERROR: Expected Image data size of 256x256x2 (without mipmaps) = 131072 bytes, got 174762 bytes instead.

ERROR: Cannot open file 'res://.import/elevator_music.ogg-66aa0f24942f3f489366fde592260f38.oggstr'.
   at: get_dependencies (core/io/resource_format_binary.cpp:984)
ERROR: Cannot open file 'res://.import/elevator_music_clear.ogg-07f2daa3449daf1116e0201ed5e734b4.oggstr'.
   at: get_dependencies (core/io/resource_format_binary.cpp:984)
ERROR: Cannot open file 'res://.import/senseless2.ogg-07d0bfb31807ffe7bee731719e8a3f2a.oggstr'.
   at: get_dependencies (core/io/resource_format_binary.cpp:984)
ERROR: Cannot open file 'res://.import/senseless3.ogg-29b41185e2b47b1887b97edb51fd486d.oggstr'.
   at: get_dependencies (core/io/resource_format_binary.cpp:984)
ERROR: Cannot open file 'res://.import/senseless4.ogg-cf591cd6a12c32b447a74982292190ea.oggstr'.
   at: get_dependencies (core/io/resource_format_binary.cpp:984)
ERROR: Cannot open file 'res://.import/senseless.ogg-79ba819268f76f9e39e5b09183435f2a.oggstr'.
   at: get_dependencies (core/io/resource_format_binary.cpp:984)
[...]
Godot Engine v3.5.rc8.official.516d6b6ba - https://godotengine.org/
reimport: begin: (Re)Importing Assets steps: 341
[...]
# build proceeds normally at this point
[exited with code 0]
```

Possibly related to #42923.

Nothing is cached except of the export templates and the Godot binary (since GHA environment is vanilla on every build).

I can provide access to GHA logs if necessary.

### Steps to reproduce

1. Export project with a headless binary in a new Docker container:  `$(GODOT_BIN) --no-window --export "Linux/X11" -q`
2. Export will fail with a ~20% chance

### Minimal reproduction project

_No response_