99 *signals that the backend can recognize.
1010 *
1111 * IDENTIFICATION
12- * $PostgreSQL: pgsql/src/port/kill.c,v 1.11 2009/01/01 17:24:04 momjian Exp $
12+ * $PostgreSQL: pgsql/src/port/kill.c,v 1.12 2009/02/15 13:58:18 mha Exp $
1313 *
1414 *-------------------------------------------------------------------------
1515 */
@@ -25,6 +25,7 @@ pgkill(int pid, int sig)
2525BYTE sigData = sig ;
2626BYTE sigRet = 0 ;
2727DWORD bytes ;
28+ int pipe_tries ;
2829
2930/* we allow signal 0 here, but it will be ignored in pg_queue_signal */
3031if (sig >=PG_SIGNAL_COUNT || sig < 0 )
@@ -39,23 +40,33 @@ pgkill(int pid, int sig)
3940return -1 ;
4041}
4142snprintf (pipename ,sizeof (pipename ),"\\\\.\\pipe\\pgsignal_%u" ,pid );
42- if (!CallNamedPipe (pipename ,& sigData ,1 ,& sigRet ,1 ,& bytes ,1000 ))
43- {
44- if (GetLastError ()== ERROR_FILE_NOT_FOUND )
45- errno = ESRCH ;
46- else if (GetLastError ()== ERROR_ACCESS_DENIED )
47- errno = EPERM ;
48- else
49- errno = EINVAL ;
50- return -1 ;
51- }
52- if (bytes != 1 || sigRet != sig )
43+
44+ /*
45+ * Writing data to the named pipe can fail for transient reasons.
46+ * Therefore, it is useful to retry if it fails. The maximum number of
47+ * calls to make was empirically determined from a 90-hour notification
48+ * stress test.
49+ */
50+ for (pipe_tries = 0 ;pipe_tries < 3 ;pipe_tries ++ )
5351{
54- errno = ESRCH ;
55- return -1 ;
52+ if (CallNamedPipe (pipename ,& sigData ,1 ,& sigRet ,1 ,& bytes ,1000 ))
53+ {
54+ if (bytes != 1 || sigRet != sig )
55+ {
56+ errno = ESRCH ;
57+ return -1 ;
58+ }
59+ return 0 ;
60+ }
5661}
5762
58- return 0 ;
63+ if (GetLastError ()== ERROR_FILE_NOT_FOUND )
64+ errno = ESRCH ;
65+ else if (GetLastError ()== ERROR_ACCESS_DENIED )
66+ errno = EPERM ;
67+ else
68+ errno = EINVAL ;
69+ return -1 ;
5970}
6071
6172#endif