Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What happens when I click the Stop button on the browser?

Tags:

java

browser

People also ask

What does the stop button on a browser do?

The stop button found in older Internet browsers is used to halt the loading of a web page.

Which button is used to stop the open web page?

Escape button in the keyboard plays an analogous role to the STOP button in the browser and stops the activity of the browser.


A Web Page load from a browser is usually a 4 step process (not considering redirections):

  1. Browser sends HTTP Request, when the Server is available
  2. Server executes code (for dynamic pages)
  3. Server sends the HTTP Response (usually HTML)
  4. Browser renders HTML, and asks for other files (images, css, ...)

The browser reaction to "Stop" depends on the step your request is at that time:

  • If your server is slow or overloaded, and you hit "Stop" during step 1, nothing happens. The browser doesn't send the request.
  • Most of the times, however, "Stop" will be hit on steps 2, 3 and 4, and in those steps your code is already executed, the browser simply stops waiting for the response (2), or receiving the response (3), or rendering the response (4).

The HTTP call itself is always a 2 steps action (Request/Response), and there is no automatic way to rollback the execution from the client


Since this question may attract attention for people not using Java, I thought I would mention PHPs behavior in regard to this question, since it is very surprising.

PHP internally maintains a status of the connection to the client. The possible values are NORMAL, ABORTED and TIMEOUT. While the connection status is NORMAL, life is good and the script will continue to execute as expected.

If the user clicks the Stop button in their browser, the connection is typically closed by the client and the status changes to ABORTED. A change of status to ABORTED will immediately end execution of the running script. As an aside, the same thing happens when the status changes to TIMEOUT (PHPs setting for the allowed run-time of scripts is exceeded).

This behavior may be useful in certain circumstances, but there are others where it could be problematic. It seems that it should be safe to abort at any time during a proper GET request; however, aborting in the middle of a request that makes a change on the server could lead to only partially completed changes.

Check out the PHP manual's entry on Connection Handling to see how to avoid complications resulting from this behavior:

http://www.php.net/manual/en/features.connection-handling.php


Generally speaking, the server will not know that you've hit stop, and the server-side process will complete. At the point that the server tries to send the response data back to the client, you may see an error because the connection was closed, but equally you may not. What you won't get is the server thread being suddenly interrupted.

You can use various elaborate mechanisms to mitigate this, like having the send send frequent ajax calls to the server that say "still waiting", and have the server perform its processing in a new thread which checks these calls, but that doesn't solve the problem completely.


The client will immediately stop transmitting data and close its connection. 9 out of 10 times your request will already have got through (perhaps due to OS buffers being "flushed" to the server). No extra information is sent to the server informing it that you stopped your request.