From 092de8cdac4697109900138e90a072166baedda3 Mon Sep 17 00:00:00 2001 From: Fabian Lange Date: Tue, 25 Nov 2014 10:26:18 +0100 Subject: always retry a status code 0 uidl request (#15254) A status code of 0 indicates that the request has not been handled by the server because the connection was closed without sending response headers. This can happen on the browser side when the browser window is closed, or it can happen on network equipment side under adverse quality of link conditions. Therefore vaadin should retry such a request once before popping up the disconnect message. Change-Id: I9524c97a3de8e4ac9499394a2a795b0441a36ead --- .../com/vaadin/client/ApplicationConnection.java | 62 +++++++++++++--------- 1 file changed, 38 insertions(+), 24 deletions(-) (limited to 'client') diff --git a/client/src/com/vaadin/client/ApplicationConnection.java b/client/src/com/vaadin/client/ApplicationConnection.java index d182706780..8c4706a701 100644 --- a/client/src/com/vaadin/client/ApplicationConnection.java +++ b/client/src/com/vaadin/client/ApplicationConnection.java @@ -66,6 +66,7 @@ import com.google.gwt.user.client.Window.ClosingHandler; import com.google.gwt.user.client.ui.HasWidgets; import com.google.gwt.user.client.ui.Widget; import com.vaadin.client.ApplicationConfiguration.ErrorMessage; +import com.vaadin.client.ApplicationConnection.ApplicationStoppedEvent; import com.vaadin.client.ResourceLoader.ResourceLoadEvent; import com.vaadin.client.ResourceLoader.ResourceLoadListener; import com.vaadin.client.communication.HasJavaScriptConnectorHelper; @@ -196,14 +197,6 @@ public class ApplicationConnection implements HasHandlers { private boolean hasActiveRequest = false; - /** - * Some browsers cancel pending XHR requests when a request that might - * navigate away from the page starts (indicated by a beforeunload event). - * In that case, we should just send the request again without displaying - * any error. - */ - private boolean retryCanceledActiveRequest = false; - /** * Webkit will ignore outgoing requests while waiting for a response to a * navigation event (indicated by a beforeunload event). When this happens, @@ -542,14 +535,6 @@ public class ApplicationConnection implements HasHandlers { Window.addWindowClosingHandler(new ClosingHandler() { @Override public void onWindowClosing(ClosingEvent event) { - /* - * Set some flags to avoid potential problems with XHR requests, - * see javadocs of the flags for details - */ - if (hasActiveRequest()) { - retryCanceledActiveRequest = true; - } - webkitMaybeIgnoringRequests = true; } }); @@ -853,6 +838,22 @@ public class ApplicationConnection implements HasHandlers { * The contents of the request to send */ protected void doUidlRequest(final String uri, final JSONObject payload) { + doUidlRequest(uri, payload, true); + } + + /** + * Sends an asynchronous or synchronous UIDL request to the server using the + * given URI. + * + * @param uri + * The URI to use for the request. May includes GET parameters + * @param payload + * The contents of the request to send + * @param retry + * true when a status code 0 should be retried + */ + protected void doUidlRequest(final String uri, final JSONObject payload, + final boolean retry) { RequestCallback requestCallback = new RequestCallback() { @Override public void onError(Request request, Throwable exception) { @@ -882,15 +883,29 @@ public class ApplicationConnection implements HasHandlers { switch (statusCode) { case 0: - if (retryCanceledActiveRequest) { + if (retry) { /* - * Request was most likely canceled because the browser - * is maybe navigating away from the page. Just send the - * request again without displaying any error in case - * the navigation isn't carried through. + * There are 2 situations where the error can pop up: + * + * 1) Request was most likely canceled because the + * browser is maybe navigating away from the page. Just + * send the request again without displaying any error + * in case the navigation isn't carried through. + * + * 2) The browser failed to establish a network + * connection. This was observed with keep-alive + * requests, and under wi-fi roaming conditions. + * + * Status code 0 does indicate that there was no server + * side processing, so we can retry the request. */ - retryCanceledActiveRequest = false; - doUidlRequest(uri, payload); + VConsole.log("Status code 0, retrying"); + (new Timer() { + @Override + public void run() { + doUidlRequest(uri, payload, false); + } + }).schedule(100); } else { handleCommunicationError( "Invalid status code 0 (server down?)", @@ -1264,7 +1279,6 @@ public class ApplicationConnection implements HasHandlers { // so setting it after used to work but not with the #8505 changes. hasActiveRequest = false; - retryCanceledActiveRequest = false; webkitMaybeIgnoringRequests = false; if (isApplicationRunning()) { -- cgit v1.2.3