Don't try to close a connection that does not exist.

This generates warnings when the connection does not exist. Instead, don't even try to close it.