Skip to content

Commit 041a155

Browse files
committed
Bug 1734262 - Suppress thread leak reports for the monitor thread. r=decoder
For the same reasons discussed in the previous commit, it's impractical to join these threads on shutdown, and so we should suppress thread leak reports for them. Differential Revision: https://phabricator.services.mozilla.com/D128651
1 parent 0668888 commit 041a155

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

mozglue/build/TsanOptions.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,14 @@ extern "C" const char* __tsan_default_suppressions() {
205205
// trigger OS-level paging. It is never joined with the main thread.
206206
"thread:StartupCache\n"
207207

208+
// Bug 1734262 - Permanent
209+
// When spawning async processes, we create a helper thread to wait for
210+
// the process to terminate in order to asynchronously report the exit
211+
// code to Gecko. This thread waits on a syscall for the process to end,
212+
// which means there's no easy way to cancel and join it during Gecko
213+
// shutdown. Suppress thread leak reports for this thread.
214+
"thread:CreateMonitorThread\n"
215+
208216
// Bug 1601600
209217
"race:SkARGB32_Blitter\n"
210218
"race:SkARGB32_Shader_Blitter\n"

xpcom/threads/nsProcess.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class nsProcess final : public nsIProcess, public nsIObserver {
4444

4545
private:
4646
~nsProcess();
47+
PRThread* CreateMonitorThread();
4748
static void Monitor(void* aArg);
4849
void ProcessComplete();
4950
nsresult CopyArgsAndRunProcess(bool aBlocking, const char** aArgs,

xpcom/threads/nsProcessCommon.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -429,9 +429,7 @@ nsresult nsProcess::RunProcess(bool aBlocking, char** aMyArgv,
429429
return NS_ERROR_FILE_EXECUTION_FAILED;
430430
}
431431
} else {
432-
mThread =
433-
PR_CreateThread(PR_SYSTEM_THREAD, Monitor, this, PR_PRIORITY_NORMAL,
434-
PR_GLOBAL_THREAD, PR_JOINABLE_THREAD, 0);
432+
mThread = CreateMonitorThread();
435433
if (!mThread) {
436434
NS_RELEASE_THIS();
437435
return NS_ERROR_FAILURE;
@@ -447,6 +445,17 @@ nsresult nsProcess::RunProcess(bool aBlocking, char** aMyArgv,
447445
return NS_OK;
448446
}
449447

448+
// We don't guarantee that monitor threads are joined before Gecko exits, which
449+
// can cause TSAN to complain about thread leaks. We handle this with a TSAN
450+
// suppression, and route thread creation through this helper so that the
451+
// suppression is as narrowly-scoped as possible.
452+
PRThread*
453+
nsProcess::CreateMonitorThread()
454+
{
455+
return PR_CreateThread(PR_SYSTEM_THREAD, Monitor, this, PR_PRIORITY_NORMAL,
456+
PR_GLOBAL_THREAD, PR_JOINABLE_THREAD, 0);
457+
}
458+
450459
NS_IMETHODIMP
451460
nsProcess::GetIsRunning(bool* aIsRunning) {
452461
if (mThread) {

0 commit comments

Comments
 (0)