2

when a client disconnects from a server request prematurely, does the server still carries out rest of the work?
specifically, in a Java Servlet doGet if I have the following code:

 public void doGet(HttpServletRequest req, HttpServletResponse res)throws ServletException, IOException { A(); //client disconnects after A(); B(); C(); } if client disconnects after A() is finished, would B and C still get executed? 

2 Answers 2

6

Yes it would. The server does not know about the disconnection up until it tries to write sth to the output stream (as a response). Event then due to a proxy server in between or because of output stream buffering it may be hard to know that a client disconnected.

Sign up to request clarification or add additional context in comments.

Comments

2

It depends.

If during A() (or any other method) you would attempt to send the response (using res) back to the client, IOException would be thrown. If not caught, it would terminate the servlet execution.

Otherwise the calculation would carry on and exit after C().

1 Comment

This may actually not be true in all cases. The response may be buffered and therefore only when the buffer is flushed you will get the exception. The other possibility is a proxy server in between, which may wait up until the whole response is sent from the server and then try to send it to the client.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.