Fix bug caused by accepting closed connections