Fix check for unexpected connection close