Fix close connection bug