2
votes

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

2 Answers

2
votes

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().

5
votes

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.