/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file.
// Maximum amount of time (in milliseconds) to wait for the process to exit. static constexpr int kWaitInterval = 2000;
// This is somewhat arbitrary, but based on Try run results. When // changing this, be aware of toolkit.asyncshutdown.crash_timeout // (currently 60s), after which the parent process will be killed. #ifdef MOZ_CODE_COVERAGE // Child processes seem to take longer to shut down on ccov builds, at // least in the wdspec tests; ~20s has been observed, and we'll spam // false positives unless this is increased. static constexpr DWORD kShutdownWaitMs = 80000; #elifdefined(MOZ_ASAN) || defined(MOZ_TSAN) // Sanitizers also slow things down in some cases; see bug 1806224. static constexpr DWORD kShutdownWaitMs = 40000; #else static constexpr DWORD kShutdownWaitMs = 20000; #endif
virtualvoid WillDestroyCurrentMessageLoop() {
MOZ_ASSERT(!force_); if (process_) { // Exception for the fake hang tests in ipc/glue/test/browser if (!PR_GetEnv("MOZ_TEST_CHILD_EXIT_HANG")) {
CrashProcessIfHanging();
}
WaitForSingleObject(process_, INFINITE);
base::CloseProcessHandle(process_);
process_ = 0;
virtualvoid OnObjectSignaled(HANDLE object) { // When we're called from KillProcess, the ObjectWatcher may still be // watching. the process handle, so make sure it has stopped.
watcher_.StopWatching();
base::CloseProcessHandle(process_);
process_ = 0;
if (!force_) {
MessageLoop::current()->RemoveDestructionObserver(this); deletethis;
}
}
private: void KillProcess() {
MOZ_ASSERT(force_);
// OK, time to get frisky. We don't actually care when the process // terminates. We just care that it eventually terminates, and that's what // TerminateProcess should do for us. Don't check for the result code since // it fails quite often. This should be investigated eventually.
TerminateProcess(process_, base::PROCESS_END_PROCESS_WAS_HUNG);
// Now, just cleanup as if the process exited normally.
OnObjectSignaled(process_);
}
// If child processes seems to be hanging on shutdown, wait for a // reasonable time. The wait is global instead of per-process // because the child processes should be shutting down in // parallel, and also we're potentially racing global timeouts // like nsTerminator. (The counter doesn't need to be atomic; // this is always called on the I/O thread.) static DWORD sWaitMs = kShutdownWaitMs; if (sWaitMs > 0) {
CHROMIUM_LOG(WARNING)
<< "Process " << pid
<< " may be hanging at shutdown; will wait for up to " << sWaitMs
<< "ms";
} constauto beforeWait = mozilla::TimeStamp::NowLoRes(); const DWORD waitStatus = WaitForSingleObject(process_, sWaitMs);
switch (waitStatus) { case WAIT_TIMEOUT: // The process is still running. break; case WAIT_OBJECT_0: // The process exited. return; case WAIT_FAILED:
CHROMIUM_LOG(ERROR) << "Waiting for process " << pid
<< " failed; error " << GetLastError();
DCHECK(false) << "WaitForSingleObject failed"; // Process status unclear; assume it's gone. return; default:
DCHECK(false) << "WaitForSingleObject returned " << waitStatus; // Again, not clear what's happening so avoid touching the process return;
}
// We want TreeHerder to flag this log line as an error, so that // this is more obviously a deliberate crash; "fatal error" is one // of the strings it looks for.
CHROMIUM_LOG(ERROR)
<< "Process " << pid
<< " hanging at shutdown; attempting crash report (fatal error)";
// We're going to use CreateRemoteThread to call DbgBreakPoint in // the target process; it's in a "known DLL" so it should be at // the same address in all processes. (Normal libraries, like // xul.dll, are usually at the same address but can be relocated // in case of conflict.) // // DbgBreakPoint doesn't take an argument, so we can give it an // arbitrary value to make it easier to identify these crash // reports. (reinterpret_cast isn't constexpr, so this is // declared as an integer and cast to the required type later.) // The primary use case for all of this is in CI, where we'll also // have log messages, but if these crashes end up in Socorro in // significant numbers then we'll be able to look for this value. static constexpr uint64_t kIpcMagic = 0x43504900435049;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.