Fix NPE when connection is null and we are trying to disconnect it