Skip to content

Commit a204ce5

Browse files
committed
Bug#21770366 backport bug#21657078 to 5.5 and 5.6
Post-push fix: The problem was that condition variable timeouts could in some cases (slow machines and/or short timeouts) be infinite. When the number of milliseconds to wait is computed, the end time is computed before the now() time. This can result in the now() time being later than the end time, leading to negative timeout. Which after conversion to unsigned becomes ~infinite. This patch fixes the problem by explicitly checking if we get negative timeout and then using 0 if this is the case.
1 parent 1624c26 commit a204ce5

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

mysys/my_wincond.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,12 @@ static DWORD get_milliseconds(const struct timespec *abstime)
127127
if (abstime == NULL)
128128
return INFINITE;
129129

130-
return (DWORD)(abstime->tv_sec * 1000 + abstime->tv_nsec / 1000000 -
131-
my_getsystime() / 10000);
130+
ulonglong future= abstime->tv_sec * 1000 + abstime->tv_nsec / 1000000;
131+
ulonglong now= my_getsystime() / 10000;
132+
/* Don't allow the timeout to be negative. */
133+
if (future < now)
134+
return 0;
135+
return (DWORD)(future - now);
132136
#endif
133137
}
134138

0 commit comments

Comments
 (0)