Check read(2) error in health_check(). This should detect case
authorTatsuo Ishii <ishii at sraoss.co.jp>
Tue, 21 Jul 2009 09:51:15 +0000 (09:51 +0000)
committerTatsuo Ishii <ishii at sraoss.co.jp>
Tue, 21 Jul 2009 09:51:15 +0000 (09:51 +0000)
described in message below, i.e. postmaster is blocked by SIGSTOP.

Subject: [Pgpool-general] Healt Check issues
From: Vctrjsn@gmail.com
To: pgpool-general@pgfoundry.org
Date: Sun, 05 Jul 2009 18:01:18 +0000

main.c

diff --git a/main.c b/main.c
index dab929dbee3db58c5dcf29d58ac4b12984efc096..88bac226c8208db944bdc2c52fd62a1443242b99 100644 (file)
--- a/main.c
+++ b/main.c
@@ -542,7 +542,7 @@ int main(int argc, char **argv)
                                        else
                                        {
                                                retrycnt++;
-                                               pool_signal(SIGALRM, SIG_IGN);
+                                               pool_signal(SIGALRM, SIG_IGN);  /* Cancel timer */
 
                                                if (retrycnt > NUM_BACKENDS)
                                                {
@@ -1394,6 +1394,7 @@ static RETSIGTYPE health_check_timer_handler(int sig)
 int health_check(void)
 {
        int fd;
+       int sts;
 
        /* V2 startup packet */
        typedef struct {
@@ -1449,7 +1450,28 @@ int health_check(void)
                        return i+1;
                }
 
-               read(fd, &kind, 1);
+               /*
+                * Don't bother to be blocked by read(2). It will be
+                * interrupted by ALRAM anyway.
+                */
+               sts = read(fd, &kind, 1);
+               if (sts == -1)
+               {
+                       pool_error("health check failed during read. host %s at port %d is down. reason: %s",
+                                          BACKEND_INFO(i).backend_hostname,
+                                          BACKEND_INFO(i).backend_port,
+                                          strerror(errno));
+                       close(fd);
+                       return i+1;
+               }
+               else if (sts == 0)
+               {
+                       pool_error("health check failed. EOF encountered. host %s at port %d is down",
+                                          BACKEND_INFO(i).backend_hostname,
+                                          BACKEND_INFO(i).backend_port);
+                       close(fd);
+                       return i+1;
+               }
 
                /*
                 * If a backend raised a FATAL error(max connections error or