Is it possible to maintain a socket connection when update code, or restart a process or hotswap code?
I'm thinking about the next generation of a distributed server application I'm working on (currently written in node.js) and I'd like to be able to keep tcp sockets open for as long as the server and the remote client have network connections, even when the server code is updated or a specific instance restarts or disappears.
Are any of the following possible?
Any reference material I should look at? It seems to me like Erlang is a good candidate for a future version of this system, but I've not used it for anything other than toy examples.
EDIT: Running on linux
Edit: fix a typo.
Well you didn't mention which platform this is running in so I will assume Linux/Unix. there are at least 2 ways to do this.
Send the app a signal which means "fork and exec your newer self". New self inherits the sockets.
You should be able to pass the socket fds via unix-pipes. You could have some minimal steward-application that will send app-v1 a signal to dump sockets to a predefined pipe, kill it when done then start app-v2 and pass it the sockets once again via unix-pipe.
Two ideas off the top of my head,
Implement the socket handlers in a separate process with a standard interface
Compile your code in dlls, this way you can load and unload the actual dlls when software updates occur.
Yes, it's possible in Erlang to swap code and transform internal state data structures according to new version. In a few words: you have to implement transform function, and call it synchronously after loading new version of code (you won't lose connections, but of course, you'll need to wait a bit for transformation is done). This feature is reliably provided in OTP (for example, if you're using gen_server
you may implement function code_change
)