-
Type: Bug
-
Resolution: Done
-
Priority: Major - P3
-
Affects Version/s: 3.0.0
-
Component/s: WiredTiger
-
None
-
Fully Compatible
-
ALL
-
The function __wt_cond_wait waits a conditional variable for usecs microseconds or for ever if the variable is zero. However, the implementation can lead to unexpected infinite wait if usecs become negative.
if (usecs > 0) { milliseconds = usecs / 1000; /* * 0 would mean the CV sleep becomes a TryCV which we do not * want */ if (milliseconds == 0) milliseconds = 1; ret = SleepConditionVariableCS( &cond->cond, &cond->mtx, milliseconds); } else ret = SleepConditionVariableCS( &cond->cond, &cond->mtx, INFINITE);
This can be fixed by reviewing the code and using unsigned values for milliseconds (as it should be a DWORD cf MSDN)
DWORD milliseconds; // .... code removed for clarity .... if (usecs == 0) { ret = SleepConditionVariableCS( &cond->cond, &cond->mtx, INFINITE); } else //if (usecs > 0) { milliseconds = ((unsigned long)usecs) / 1000UL; /* * 0 would mean the CV sleep becomes a TryCV which we do not * want */ if (milliseconds == 0) milliseconds = 1; ret = SleepConditionVariableCS( &cond->cond, &cond->mtx, milliseconds); }