From: Huahui Wu Date: Tue, 19 Apr 2011 15:58:00 +0000 (-0700) Subject: b/3491968 stop the hanging of dunkindonuts.com X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=1360c55ddd4e5ce56a558c055de5b09d250c51b4;p=android-x86%2Fexternal-webkit.git b/3491968 stop the hanging of dunkindonuts.com Same as https://android-git.corp.google.com/g/#change,105743 but in Master. Changed the waiting to 10 seconds each attempt after asking around. Sometimes, a sync load can wait forever and lock up the network thread, here we replace Wait() with TimedWait() with multiple tries to avoid locking. Unfortunately, TimedWait() doesn't return anything and can't tell if it's a timeout or a quick pass, so we query timeofday and allow a few seconds for the system timing error. Change-Id: I391fb3f815413f17b2927c1e90cbddab7faed071 --- diff --git a/WebKit/android/WebCoreSupport/WebUrlLoaderClient.cpp b/WebKit/android/WebCoreSupport/WebUrlLoaderClient.cpp index fcfb4ca50..cf218e71a 100644 --- a/WebKit/android/WebCoreSupport/WebUrlLoaderClient.cpp +++ b/WebKit/android/WebCoreSupport/WebUrlLoaderClient.cpp @@ -180,14 +180,29 @@ bool WebUrlLoaderClient::start(bool isMainResource, bool isMainFrame, bool sync, thread->message_loop()->PostTask(FROM_HERE, NewRunnableMethod(m_request.get(), &WebRequest::start)); // Run callbacks until the queue is exhausted and m_finished is true. + // Sometimes, a sync load can wait forever and lock up the WebCore thread, + // here we use TimedWait() with multiple tries to avoid locking. + const int kMaxNumTimeout = 3; + const int kCallbackWaitingTime = 10; + int num_timeout = 0; while(!m_finished) { while (!m_queue.empty()) { OwnPtr task(m_queue.front()); m_queue.pop_front(); task->Run(); } - if (m_queue.empty() && !m_finished) { - syncCondition()->Wait(); + if (m_finished) break; + + syncCondition()->TimedWait(base::TimeDelta::FromSeconds(kCallbackWaitingTime)); + if (m_queue.empty()) { + LOGE("Synchronous request timed out after %d seconds for the %dth try, URL: %s", + kCallbackWaitingTime, num_timeout, m_request->getUrl().c_str()); + num_timeout++; + if (num_timeout >= kMaxNumTimeout) { + cancel(); + m_resourceHandle = 0; + return false; + } } }