Fix bug of keepalive logic.