Check if connection exist before closing connection