Fix authentication timeout that can occur right after client connecttions
authorYugo Nagata <nagata@sraoss.co.jp>
Wed, 28 Dec 2016 09:07:28 +0000 (18:07 +0900)
committerYugo Nagata <nagata@sraoss.co.jp>
Wed, 28 Dec 2016 09:09:32 +0000 (18:09 +0900)
This is possible when connection_life_time is enabled.

SIGALRM signal is used for both connection_life_time and
authentication_timeout. Usually, SIGALRM is for connection_life_time,
but when the new connection is arrive, read_startup_packet() is called,
and the handler for authentication_timeout is set by pool_signal() and
alarm(authentication_timeout) is called in enable_authentication_timeout().

However, if connection_life_time is expired **between pool_signal() and
alarm()**, authenticate_timeout() will be called when connection_life_time
is expired instead of pool_backend_timer_handler().

To fix this, call alarm() before pool_signal() to prevent the signal
handler from being with wrong timing.

child.c

diff --git a/child.c b/child.c
index aa9b31e1b267852ea17042558676123138ba828a..166ae0064971906394c99a50626b79399d110f3b 100644 (file)
--- a/child.c
+++ b/child.c
@@ -847,8 +847,8 @@ static StartupPacket *read_startup_packet(POOL_CONNECTION *cp)
 
        if (pool_config->authentication_timeout > 0)
        {
-               pool_signal(SIGALRM, authentication_timeout);
                alarm(pool_config->authentication_timeout);
+               pool_signal(SIGALRM, authentication_timeout);
        }
 
        /* read startup packet length */