diff options
author | Miguel Costa <miguel.costa@qt.io> | 2021-08-05 15:15:55 +0200 |
---|---|---|
committer | Miguel Costa <miguel.costa@qt.io> | 2021-08-09 13:03:11 +0000 |
commit | a82142dfe3cf6c312ee88c9e3e4e65189f58b902 (patch) | |
tree | 31913ddbb086879031ae6f589af1654d62dae210 /src | |
parent | ac101910a367b3c34b3fb12ac758dd3d583fa62a (diff) |
Fix possible thread starvation issue
When a target in Qt/MSBuild requests access to a critical section,
a timeout of 10 seconds will now be enforced to prevent a starvation
scenario, in case of leak of the critical section (e.g. the target that
owns the critical section was terminated without running the fail-safe
release of the critical section).
Fixes: QTVSADDINBUG-917
Change-Id: Ie357152ac6ec208d33a5acfa07a45ace0b1f041f
Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/qtmsbuild/Tasks/CriticalSection.cs | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/src/qtmsbuild/Tasks/CriticalSection.cs b/src/qtmsbuild/Tasks/CriticalSection.cs index 52159e81..b75f5bde 100644 --- a/src/qtmsbuild/Tasks/CriticalSection.cs +++ b/src/qtmsbuild/Tasks/CriticalSection.cs @@ -83,14 +83,22 @@ namespace QtVsTools.QtMsBuild.Tasks } if (Lock) { // Wait until locked - while (!buildLock.WaitOne(3000)) { - // Check every 3 secs. for build errors - if (Log.HasLoggedErrors) { - Log.LogError("Qt::BuildLock[{0}]: Errors logged; wait aborted", Name); - return false; - } - // Issue "still waiting" warning + if (!buildLock.WaitOne(1000)) { + // Issue waiting warning Log.LogWarning("Qt::BuildLock[{0}]: Waiting...", Name); + var t = Stopwatch.StartNew(); + do { + // Check for build errors + if (Log.HasLoggedErrors) { + Log.LogError("Qt::BuildLock[{0}]: Errors logged; wait aborted", Name); + return false; + } + // Timeout after 10 secs. + if (t.ElapsedMilliseconds >= 10000) { + Log.LogError("Qt::BuildLock[{0}]: Timeout; wait aborted", Name); + return false; + } + } while (!buildLock.WaitOne(1000)); } } else { // Unlock |