Fix connection closing behavior