Fix cases where it may close a connection that does not exist.