Close connection after a read or write error