Do most people just restart their Rust web servers once every three months?

266 points redditaccount624

So I've noticed a problem where my Rust servers stop accepting new connections after three months until I restart them.

I've now realized that the issue is because because the local LetsEncrypt certificate on the my remote server instance only lasts for 3 months. Yes, it is automatically renewed and the local file is automatically replaced every two months, but my Rust web server doesn't know that and it still has the old one loaded in memory.

So, to grab the new certificate I need to restart the server so it loads in the fresh certificate. However, I use websockets and in this case it would interrupt everyone's connection. I'd rather not have to restart the server if possible.

But then what do I do? One of my first ideas was to an async loop where I await a 30 day timer (is this crazy?) and hot-reload the certificate when that occurs, but I don't know if tokio timers would even work for that long of a duration?

Also, I'm not sure how I would technically even replace the existing TlsAcceptor in my program. Currently it's just a plain old variable, but if I did this, then wouldn't it need to be an Arc<Mutex>> or use a channel or something? Because I would need an independent tokio task (which runs once every 30 days) to update the value of this variable from elsewhere. I was having issues with the borrow checker when I tried to do this without synchronization.

In that case I am now incurring the overhead of accessing this Arc or Channel or whatever with every incoming connection, which seems a bit unfortunate, because that value would only be changing once every 30 days.

I guess the other option is to not use secure websockets at all? I'm trying to think.. do I even need to? Because the user is connecting to a frontend which is hosted on Netlify and that already has a certificate. So am I like, double encrypting right now? Could I do a secure websocket connection to a Rust web server that is using non-TLS websockets because the domain already has a free certificate from Netlify? Not sure..