Fail early if there is no network connection

Part of work on #2025.
Try to relog if needed when connectivity reappears

Part of work on #2025.
Merge pull request #4477 from samueltardieu/issue-2025

fix #2025: do not issue unnecessary login attempts