Bug 1635196 - Make sure profile-gathering promise is fulfilled before destroying holder - r=mstange

While gathering profiles from child processes, some actions (e.g., shutting down, restarting the profiler) may reset the gathering operation.
In this case we must ensure that the promise is rejected if not already fulfilled, so that anyone waiting on it won't be blocked forever (and MozPromise enforces it in a MOZ_DIAGNOSTIC_ASSERT).

Differential Revision: https://phabricator.services.mozilla.com/D73790
This commit is contained in:
Gerald Squelart 2020-05-05 21:07:34 +00:00
Родитель d8308aa13f
Коммит 52ffb43ad5
1 изменённых файлов: 7 добавлений и 5 удалений

Просмотреть файл

@ -59,6 +59,7 @@ nsProfiler::~nsProfiler() {
if (mSymbolTableThread) {
mSymbolTableThread->Shutdown();
}
ResetGathering();
}
nsresult nsProfiler::Init() {
@ -143,10 +144,6 @@ nsProfiler::StartProfiler(uint32_t aEntries, double aInterval,
NS_IMETHODIMP
nsProfiler::StopProfiler() {
// If we have a Promise in flight, we should reject it.
if (mPromiseHolder.isSome()) {
mPromiseHolder->RejectIfExists(NS_ERROR_DOM_ABORT_ERR, __func__);
}
ResetGathering();
profiler_stop();
@ -921,7 +918,12 @@ void nsProfiler::FinishGathering() {
}
void nsProfiler::ResetGathering() {
mPromiseHolder.reset();
// If we have an unfulfilled Promise in flight, we should reject it before
// destroying the promise holder.
if (mPromiseHolder.isSome()) {
mPromiseHolder->RejectIfExists(NS_ERROR_DOM_ABORT_ERR, __func__);
mPromiseHolder.reset();
}
mPendingProfiles = 0;
mGathering = false;
mWriter.reset();