aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2012-11-18 15:39:51 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2012-11-18 15:39:51 -0500
commit14ddff44c22cb358775d5aad6953f0ce0fdb64cf (patch)
treefa336b01ed9170ddbeff676151a372e6b9cb6280
parent6b6633ad6cf663c81b5e0bc0c40709bf9d8d0299 (diff)
downloadpostgresql-14ddff44c22cb358775d5aad6953f0ce0fdb64cf.tar.gz
postgresql-14ddff44c22cb358775d5aad6953f0ce0fdb64cf.zip
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.
-rw-r--r--src/backend/port/unix_latch.c10
-rw-r--r--src/backend/port/win32_latch.c3
2 files changed, 8 insertions, 5 deletions
diff --git a/src/backend/port/unix_latch.c b/src/backend/port/unix_latch.c
index 29ef38226aa..d3b2247f052 100644
--- a/src/backend/port/unix_latch.c
+++ b/src/backend/port/unix_latch.c
@@ -33,6 +33,7 @@
#include "postgres.h"
#include <fcntl.h>
+#include <limits.h>
#include <signal.h>
#include <unistd.h>
#include <sys/time.h>
@@ -176,9 +177,10 @@ DisownLatch(volatile Latch *latch)
* to wait for. If the latch is already set (and WL_LATCH_SET is given), the
* function returns immediately.
*
- * The 'timeout' is given in milliseconds. It must be >= 0 if WL_TIMEOUT flag
- * is given. Note that some extra overhead is incurred when WL_TIMEOUT is
- * given, so avoid using a timeout if possible.
+ * The "timeout" is given in milliseconds. It must be >= 0 if WL_TIMEOUT flag
+ * is given. Although it is declared as "long", we don't actually support
+ * timeouts longer than INT_MAX milliseconds. Note that some extra overhead
+ * is incurred when WL_TIMEOUT is given, so avoid using a timeout if possible.
*
* The latch must be owned by the current process, ie. it must be a
* backend-local latch initialized with InitLatch, or a shared latch
@@ -243,7 +245,7 @@ WaitLatchOrSocket(volatile Latch *latch, int wakeEvents, pgsocket sock,
if (wakeEvents & WL_TIMEOUT)
{
INSTR_TIME_SET_CURRENT(start_time);
- Assert(timeout >= 0);
+ Assert(timeout >= 0 && timeout <= INT_MAX);
cur_timeout = timeout;
#ifndef HAVE_POLL
diff --git a/src/backend/port/win32_latch.c b/src/backend/port/win32_latch.c
index 95370d9d58d..575035c28d4 100644
--- a/src/backend/port/win32_latch.c
+++ b/src/backend/port/win32_latch.c
@@ -20,6 +20,7 @@
#include "postgres.h"
#include <fcntl.h>
+#include <limits.h>
#include <signal.h>
#include <unistd.h>
@@ -130,7 +131,7 @@ WaitLatchOrSocket(volatile Latch *latch, int wakeEvents, pgsocket sock,
if (wakeEvents & WL_TIMEOUT)
{
INSTR_TIME_SET_CURRENT(start_time);
- Assert(timeout >= 0);
+ Assert(timeout >= 0 && timeout <= INT_MAX);
cur_timeout = timeout;
}
else