Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 14ddff4

Browse files
committed
Assert that WaitLatch's timeout is not more than INT_MAX milliseconds.
The behavior with larger values is unspecified by the Single Unix Spec. It appears that BSD-derived kernels report EINVAL, although Linux does not. If waiting for longer intervals is desired, the calling code has to do something to limit the delay; we can't portably fix it here since "long" may not be any wider than "int" in the first place. Part of response to bug #7670, though this change doesn't fix that (in fact, it converts the problem from an ERROR into an Assert failure). No back-patch since it's just an assertion addition.
1 parent 6b6633a commit 14ddff4

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/backend/port/unix_latch.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "postgres.h"
3434

3535
#include <fcntl.h>
36+
#include <limits.h>
3637
#include <signal.h>
3738
#include <unistd.h>
3839
#include <sys/time.h>
@@ -176,9 +177,10 @@ DisownLatch(volatile Latch *latch)
176177
* to wait for. If the latch is already set (and WL_LATCH_SET is given), the
177178
* function returns immediately.
178179
*
179-
* The 'timeout' is given in milliseconds. It must be >= 0 if WL_TIMEOUT flag
180-
* is given. Note that some extra overhead is incurred when WL_TIMEOUT is
181-
* given, so avoid using a timeout if possible.
180+
* The "timeout" is given in milliseconds. It must be >= 0 if WL_TIMEOUT flag
181+
* is given. Although it is declared as "long", we don't actually support
182+
* timeouts longer than INT_MAX milliseconds. Note that some extra overhead
183+
* is incurred when WL_TIMEOUT is given, so avoid using a timeout if possible.
182184
*
183185
* The latch must be owned by the current process, ie. it must be a
184186
* backend-local latch initialized with InitLatch, or a shared latch
@@ -243,7 +245,7 @@ WaitLatchOrSocket(volatile Latch *latch, int wakeEvents, pgsocket sock,
243245
if (wakeEvents & WL_TIMEOUT)
244246
{
245247
INSTR_TIME_SET_CURRENT(start_time);
246-
Assert(timeout >= 0);
248+
Assert(timeout >= 0 && timeout <= INT_MAX);
247249
cur_timeout = timeout;
248250

249251
#ifndef HAVE_POLL

src/backend/port/win32_latch.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "postgres.h"
2121

2222
#include <fcntl.h>
23+
#include <limits.h>
2324
#include <signal.h>
2425
#include <unistd.h>
2526

@@ -130,7 +131,7 @@ WaitLatchOrSocket(volatile Latch *latch, int wakeEvents, pgsocket sock,
130131
if (wakeEvents & WL_TIMEOUT)
131132
{
132133
INSTR_TIME_SET_CURRENT(start_time);
133-
Assert(timeout >= 0);
134+
Assert(timeout >= 0 && timeout <= INT_MAX);
134135
cur_timeout = timeout;
135136
}
136137
else

0 commit comments

Comments
 (0)