0

I have a websocket nodejs server and a client.

I observed that when I force kill -9 the server process, the client connection is automatically closed. How does the client know about it? More importantly, is it even possible for the client to remain connected without knowing the server is dead?

On one hand I think this case might be impossible based on my observation, but on the other hand, without understanding how it works I cannot be too optimistic.

I also tried shutting down a virtualbox machine running the server forcefully (via vagrant halt -f, also tried kill -9 the virtual machine process on host machine) according to this post: What is the most violent way that an application can terminate itself (linux) and the client websocket connection also magically terminates itself.

Any help would be appreciated.

cr001
  • 655
  • 4
  • 16
  • (1) The operating system either closes or resets open sockets (and other things) when a process exits, depending on whether it isn't or is Windows. (2) 'More importantly, is it even possible for the client to remain connected without knowing the server is dead?': it does know: see (1). – user207421 Jul 21 '22 at 10:12
  • But how could it explain the connection closing when I run the server on a virtual machine and kill the VM process forcefully. One thing I couldn't test is actually unplugging the power as I only have one computer to run both server and client, but killing the VM process should be the same though. – cr001 Jul 21 '22 at 10:19
  • I've already explained it. See (1) above. Same process. – user207421 Jul 21 '22 at 11:31
  • Maybe I did not understand correctly, but shouldn't a power halt terminate all OS kernel processing immediately? Then it won't be able to send any close signal or reset signal, right? If you could explain a little bit more I would appreciate. – cr001 Jul 21 '22 at 11:38

0 Answers0