From ac5d2c4f89544252973d62d33277625705469c05 Mon Sep 17 00:00:00 2001 From: lordmulder Date: Sat, 11 Feb 2012 16:10:21 +0100 Subject: [PATCH] Improved deadlock handling. We will now throw a warning after 1 minute and abort after 5 minutes of inactivity. This may still be too short for FFVideoSource() to finish indexing on extremely large files. Though in this case the user should use 'ffmsindex' to create the index beforehand. --- src/thread_encode.cpp | 36 ++++++++++++++++++++++++++++-------- src/thread_encode.h | 4 +++- src/version.h | 2 +- 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/src/thread_encode.cpp b/src/thread_encode.cpp index b6e5c9d..f8c93d1 100644 --- a/src/thread_encode.cpp +++ b/src/thread_encode.cpp @@ -345,11 +345,11 @@ bool EncodeThread::runEncodingPass(bool x264_x64, bool avs2yuv_x64, bool usePipe waitCounter = 0; continue; } - if(!processEncode.waitForReadyRead(2500)) + if(!processEncode.waitForReadyRead(m_processTimeoutInterval)) { if(processEncode.state() == QProcess::Running) { - if(waitCounter++ > m_processTimeoutCounter) + if(waitCounter++ > m_processTimeoutMaxCounter) { processEncode.kill(); qWarning("x264 process timed out <-- killing!"); @@ -357,6 +357,11 @@ bool EncodeThread::runEncodingPass(bool x264_x64, bool avs2yuv_x64, bool usePipe bTimeout = true; break; } + else if(waitCounter == m_processTimeoutWarning) + { + unsigned int timeOut = (waitCounter * m_processTimeoutInterval) / 1000U; + log(tr("Warning: x264 did not respond for %1 seconds, potential deadlock...").arg(QString::number(timeOut))); + } continue; } } @@ -764,6 +769,8 @@ bool EncodeThread::checkProperties(bool x64, unsigned int &frames) unsigned int fSizeW = 0; unsigned int fSizeH = 0; + unsigned int waitCounter = 0; + while(process.state() != QProcess::NotRunning) { if(m_abort) @@ -772,17 +779,30 @@ bool EncodeThread::checkProperties(bool x64, unsigned int &frames) bAborted = true; break; } - if(!process.waitForReadyRead()) + if(!process.waitForReadyRead(m_processTimeoutInterval)) { if(process.state() == QProcess::Running) { - process.kill(); - qWarning("Avs2YUV process timed out <-- killing!"); - log("\nPROCESS TIMEOUT !!!"); - bTimeout = true; - break; + if(waitCounter++ > m_processTimeoutMaxCounter) + { + process.kill(); + qWarning("Avs2YUV process timed out <-- killing!"); + log("\nPROCESS TIMEOUT !!!"); + log("\nAvisynth has encountered a deadlock or your script takes EXTREMELY long to initialize!"); + bTimeout = true; + break; + } + else if(waitCounter == m_processTimeoutWarning) + { + unsigned int timeOut = (waitCounter * m_processTimeoutInterval) / 1000U; + log(tr("Warning: Avisynth did not respond for %1 seconds, potential deadlock...").arg(QString::number(timeOut))); + } } + continue; } + + waitCounter = 0; + while(process.bytesAvailable() > 0) { QList lines = process.readLine().split('\r'); diff --git a/src/thread_encode.h b/src/thread_encode.h index 9d26cc8..e6904f5 100644 --- a/src/thread_encode.h +++ b/src/thread_encode.h @@ -79,7 +79,9 @@ public: protected: static QMutex m_mutex_startProcess; - static const int m_processTimeoutCounter = 24; + static const unsigned int m_processTimeoutInterval = 2500; + static const unsigned int m_processTimeoutMaxCounter = 120; + static const unsigned int m_processTimeoutWarning = 24; //Constants const QUuid m_jobId; diff --git a/src/version.h b/src/version.h index 5a1f3a0..9761216 100644 --- a/src/version.h +++ b/src/version.h @@ -22,7 +22,7 @@ #define VER_X264_MAJOR 2 #define VER_X264_MINOR 0 #define VER_X264_PATCH 1 -#define VER_X264_BUILD 119 +#define VER_X264_BUILD 126 #define VER_X264_MINIMUM_REV 2146 #define VER_X264_CURRENT_API 120