Fix authentication timeout that can occur right after client connecttions
authorYugo Nagata <nagata@sraoss.co.jp>
Wed, 28 Dec 2016 08:37:11 +0000 (17:37 +0900)
committerYugo Nagata <nagata@sraoss.co.jp>
Wed, 28 Dec 2016 08:37:11 +0000 (17:37 +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.

src/protocol/child.c

index 843db9281cc3b4148c151721a7b81ebf7d085077..db58723396bb8088a3e21cbce93b21ae258ca5d1 100644 (file)
@@ -1034,8 +1034,8 @@ static void enable_authentication_timeout(void)
 {
        if(pool_config->authentication_timeout <= 0)
                return;
-       pool_signal(SIGALRM, authentication_timeout);
        alarm(pool_config->authentication_timeout);
+       pool_signal(SIGALRM, authentication_timeout);
        alarm_enabled = true;
 }