fix to close if an error raises even in keepalive mode