From f1a192bd518ee9a181a2577f67f7f68522fb7e7a Mon, 16 Jan 2012 01:12:25 +0100 From: Stevo Slavic Date: Mon, 16 Jan 2012 01:10:46 +0100 Subject: [PATCH] Fixes triggering failover only with health check. Fixes health check timeout not being respected when icmp host unreachable messages are dropped for security reasons. diff --git a/child.c b/child.c index 3dfa460..49daab6 100644 --- a/child.c +++ b/child.c @@ -76,7 +76,7 @@ POOL_CONNECTION_POOL *backend, StartupPacket *sp); /* - * non 0 means SIGTERM(smart shutdown) or SIGINT(fast shutdown) has arrived + * non 0 means SIGTERM(smart shutdown) or SIGINT(fast shutdown) has arrived, or SIGALRM (health check timeout) */ volatile sig_atomic_t exit_request = 0; diff --git a/main.c b/main.c index 123e899..77d55f4 100644 --- a/main.c +++ b/main.c @@ -693,13 +693,12 @@ retrycnt++; pool_signal(SIGALRM, SIG_IGN); /* Cancel timer */ + /* + * Not parallel query mode case + */ if (!pool_config->parallel_mode) { - if (POOL_DISALLOW_TO_FAILOVER(BACKEND_INFO(sts).flag)) - { - pool_log("health_check: %d failover is canceld because failover is disallowed", sts); - } - else if (retrycnt <= pool_config->health_check_max_retries) + if (retrycnt <= pool_config->health_check_max_retries) { /* continue to retry */ sleep_time = pool_config->health_check_retry_delay; @@ -718,6 +717,10 @@ /* need to distribute this info to children */ } } + + /* + * Not parallel query mode case + */ else { if (retrycnt > NUM_BACKENDS) @@ -1924,6 +1927,7 @@ { POOL_SETMASK(&BlockSig); health_check_timer_expired = 1; + exit_request = sig; POOL_SETMASK(&UnBlockSig); } diff --git a/pool_connection_pool.c b/pool_connection_pool.c index fa6f628..8ac1245 100644 --- a/pool_connection_pool.c +++ b/pool_connection_pool.c @@ -545,20 +545,22 @@ (char *) hp->h_addr, hp->h_length); + pool_set_nonblock(fd); + for (;;) { if (exit_request) /* exit request already sent */ { pool_log("connect_inet_domain_socket_by_port: exit request has been sent"); + close(fd); return -1; } if (connect(fd, (struct sockaddr *)&addr, len) < 0) { - if ((errno == EINTR && retry) || errno == EAGAIN) + if ((errno == EINTR && retry) || errno == EAGAIN || errno == EINPROGRESS || errno == EALREADY) continue; - pool_error("connect_inet_domain_socket: connect() failed: %s",strerror(errno)); close(fd); return -1; }