Index: main.c
===================================================================
RCS file: /cvsroot/pgpool/pgpool-II/main.c,v
retrieving revision 1.94
diff -u -r1.94 main.c
--- main.c	30 Mar 2011 02:13:07 -0000	1.94
+++ main.c	30 Mar 2011 10:34:58 -0000
@@ -123,6 +123,7 @@
 									int old_master, int new_master, int old_primary);
 
 static int find_primary_node(void);
+static int find_primary_node_repeatedly(void);
 
 static struct sockaddr_un un_addr;		/* unix domain socket path */
 static struct sockaddr_un pcp_un_addr;  /* unix domain socket path for PCP */
@@ -1602,7 +1603,7 @@
 	 * all backends as they are not replicated anymore
 	 */
 	int follow_cnt = 0;
-	new_primary =  find_primary_node();
+	new_primary =  find_primary_node_repeatedly();
 	if (MASTER_SLAVE && !strcmp(pool_config->master_slave_sub_mode, MODE_STREAMREP))
 	{
 		/* only if the failover is against the current primary */
@@ -2374,7 +2375,7 @@
 		if (!s)
 		{
 			pool_error("find_primary_node: make_persistent_connetcion failed");
-			break;
+			return -1;
 		}
 		con = s->con;
 
@@ -2400,7 +2401,7 @@
 			return -1;
 		}
 
-		status = do_query(con, "SELECT pg_is_in_recovery() AND pgpool_walrecrunning()",
+		status = do_query(con, "SELECT pg_is_in_recovery()",
 						  &res, PROTO_MAJOR_V3);
 		if (res->numrows <= 0)
 		{
@@ -2444,6 +2445,21 @@
 	return i;
 }
 
+static int find_primary_node_repeatedly(void)
+{
+	int sec;
+	int node_id = -1;
+
+	for (sec = 0; sec < pool_config->recovery_timeout; sec++)
+	{
+		node_id = find_primary_node();
+		if (node_id != -1)
+			break;
+		pool_sleep(1);
+	}
+	return node_id;
+}
+
 /*
 * fork a follow child
 */
