aboutsummaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
authorFabian Lange <lange.fabian@gmail.com>2014-11-25 10:26:18 +0100
committerSauli Tähkäpää <sauli@vaadin.com>2014-12-16 22:46:25 +0200
commit092de8cdac4697109900138e90a072166baedda3 (patch)
tree07930560646125bb622ff8b61e52050eb1741775 /client
parenta8a480cc92efb15c83833b4a87a0475b6802e57c (diff)
downloadvaadin-framework-092de8cdac4697109900138e90a072166baedda3.tar.gz
vaadin-framework-092de8cdac4697109900138e90a072166baedda3.zip
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
Diffstat (limited to 'client')
-rw-r--r--client/src/com/vaadin/client/ApplicationConnection.java62
1 files changed, 38 insertions, 24 deletions
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;
@@ -197,14 +198,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,
* we should keep trying to send the request every now and then until there
@@ -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()) {