2

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?

GhostCat
  • 137,827
  • 25
  • 176
  • 248
Leonardo Coelho
  • 175
  • 2
  • 10

1 Answers1

1

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.

GhostCat
  • 137,827
  • 25
  • 176
  • 248
  • Thanks for your explanation :) So, for what I've understood, one possble approach is: In the client, to define a timeout that will say: when the thread send a message, it wait X time for the reply, otherwise it proceeds. Is it right? – Leonardo Coelho Jun 29 '17 at 08:58
  • From a 10K view; yes. But of course, in reality things are more difficult. As written, you can specify timeouts on socket objects. But one has to understand when those timeouts actually kick in. And of course, that is on the TCP layer. And that "layer" is something that you normally might want to "hide" from most of your code. But please understand: this is really a "huge" topic. If I would have more specific advise, i would have written that down already ;-) – GhostCat Jun 29 '17 at 09:04