Invoke 'disconnect' on exit only if we are connected