How to avoid losing connection during apt/dpkg package upgrade?

Tailscale went down during package upgrades on Ubuntu 18.04 and remained that way until I responded to a debconf question about a different package. Had I been exclusively reliant on Tailscale networking for remote access, the machine presumably would have been left inaccessible until after I gained physical access to it.

How can I avoid this in the future?

While connected to said machine via SSH and Tailscale, I ran aptitude update followed by aptitude safe-upgrade, affirmed that I wanted to upgrade a variety of packages, saw the typical messages scroll by, and then:

Preparing to unpack .../tailscale_1.3.190_amd64.deb ...
Shared connection to 100.83.125.63 closed.

Seconds later, and also several minutes later, I was unable to reconnect on the machine’s tailscale interface, and tailscale ping for the machine timed out.

Fortunately, I had been in screen session, and was able to reattach via traditional networking. I found a full-screen debconf dialog box awaiting input regarding a different package. I responded, then saw several lines of output from aptitude, concluding with:

Setting up tailscale (1.3.190) ...
Current status: 1 (-9) upgradable.

I disconnected, then immediately reconnected via tailscale.

It appears that I was upgrading from tailscale v1.3.165 to v1.3.190:

$ grep tailscale /var/log/dpkg.log | tail -n15
2021-01-05 07:59:47 status unpacked tailscale:amd64 1.3.165
2021-01-05 07:59:47 status half-configured tailscale:amd64 1.3.165
2021-01-05 07:59:48 status installed tailscale:amd64 1.3.165
2021-01-21 19:37:38 upgrade tailscale:amd64 1.3.165 1.3.190
2021-01-21 19:37:38 status half-configured tailscale:amd64 1.3.165
2021-01-21 19:37:40 status unpacked tailscale:amd64 1.3.165
2021-01-21 19:37:40 status half-installed tailscale:amd64 1.3.165
2021-01-21 19:37:41 status half-installed tailscale:amd64 1.3.165
2021-01-21 19:37:42 status unpacked tailscale:amd64 1.3.190
2021-01-21 19:37:42 status unpacked tailscale:amd64 1.3.190
2021-01-21 20:34:46 configure tailscale:amd64 1.3.190 <none>
2021-01-21 20:34:46 status unpacked tailscale:amd64 1.3.190
2021-01-21 20:34:46 status unpacked tailscale:amd64 1.3.190
2021-01-21 20:34:46 status half-configured tailscale:amd64 1.3.190
2021-01-21 20:34:47 status installed tailscale:amd64 1.3.190

I think you’ve answered your own question. I was going to suggest that you use screen to get back to your session once tailscale came back on line, but you are already doing that. I think the best solution would be to update tailscale first, wait for the service bounce and once it’s back on line complete your system update. At least that’s how I do it.

Related discussion: https://twitter.com/pmocek/status/1354650098987397121