Leonardo Coelho
Leonardo Coelho

Reputation: 185

What happen to a thread on a server crash?

Let's say I am following a client-server model, and one client, which is actually a thread, block on the remote server, which is actually a monitor.

What will happen to that thread, if the server crashes for some reason?

Upvotes: 2

Views: 218

Answers (1)

GhostCat
GhostCat

Reputation: 140457

Answer is: it depends:

  • it is possible that this thread just sits there; waiting forever.
  • but it is also possible that an exception is thrown at some point; and that thread somehow gets back "alive".

Things that play a role here:

  • the underlying TCP stack
  • your usage of that (for example it is possible to give timeout values to sockets; which cause exceptions to be thrown on timeout situations)
  • how exactly your client is coded

In other words: nobody can tell you what your client application will be doing. Because we do not have any information about the implementation and configuration details you are dealing with.

Or, changing perspective: you should make sure that your client uses some form of timeouts. As said, this could be done by setting a timeout on the sockets used for communication. Or by having another thread that monitors all threads talking to a server; and that kicks in at some point in order to prevent such threads from waiting forever.

Long story short: if you are serious about such issues; you have to do a lot of research; a good starting point would be the old classic "Release it" by Michael Nygard.

Upvotes: 1

Related Questions