When an error occurs we wont have always a connection to end. Calling end on undefined would produce more errors