Answer the question
In order to leave comments, you need to log in
How to reload a service in Go so as to keep current WS connections?
I have a Go service that has a large number of Websocket clients listening for data. Like, around the clock, and it is undesirable for the connection to break. Let's say I need to update a service. Is it possible to reboot it so that clients don't have to reconnect?
Actually, I see two options so far:
a) put such functionality on the client side (which I also write, but I would not like to do this): the service sends a message about its reboot, and the client tries to reconnect after a while.
b) split the server into two parts, one is just logic, the other is just servicing connections, interacting through MongoDB Capped Collection (which would actually work: the data gets rotten over time, but the question is its performance: you need to send data as soon as possible).
Perhaps there is some more elegant/native solution?
Thanks in advance.
Thank you.
Answer the question
In order to leave comments, you need to log in
there is such a thing as https://golang.org/pkg/plugin/
I don’t know if it will work, but if it does, then divide the application into 2 parts - one is the web server, the second is all the logic that is connected as a plugin. Here, as far as I understand, it can be changed in a hot way.
If it doesn’t work, and the issue of saving connections is critical, then it’s still divided into two parts, but they must communicate with each other over some kind of IPC channel (tcp / unix / whaterver) . This will allow the second part to be reloaded without touching the first.
In what a problem to make on the client reconnection at breakage? In any case, this should be done in case of problems connecting to the Internet at the client.
If it’s absolutely impossible to have downtime, you can first launch a new service, transfer all connections from clients to it, and only then turn off the old one. True, IMHO, this is much more zaparno than auto-reconnect on the client.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question