Bug 1919556 - FS: Call the callback immediately if there are no promises to settle in FileSystemManagerChild::CloseAllWritables; r=dom-storage-reviewers,jari

FileSystemManagerChild::CloseAllWritables is sometimes called from
FileSystemManager::Shutdown which can be called late in application shutdown
when GetCurrentSerialEventTarget returns null. At that point there are no
writable file streams and the problem with GetCurrentSerialEventTarget
returning null can be solved by calling the callback directly without
dispatching a new runnable.

Differential Revision: https://phabricator.services.mozilla.com/D221614
This commit is contained in:
Jan Varga 2024-10-03 22:38:29 +00:00
parent 174389c55c
commit dd3b50210c

View File

@ -27,6 +27,17 @@ void FileSystemManagerChild::CloseAllWritables(
nsTArray<RefPtr<BoolPromise>> promises;
CloseAllWritablesImpl(promises);
// FileSystemManagerChild::CloseAllWritables is sometimes called from
// FileSystemManager::Shutdown which can be called late in app shutdown
// when GetCurrentSerialEventTarget returns null. At that point there
// are no writable file streams. The problem with GetCurrentSerialEventTarget
// returning null can be solved by calling the callback directly without
// dispatching a new runnable.
if (promises.IsEmpty()) {
aCallback();
return;
}
BoolPromise::AllSettled(GetCurrentSerialEventTarget(), promises)
->Then(GetCurrentSerialEventTarget(), __func__,
[callback = std::move(aCallback)](