aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabian Lange <lange.fabian@gmail.com>2014-11-25 10:26:18 +0100
committerVaadin Code Review <review@vaadin.com>2014-12-10 12:36:11 +0000
commitab9d395d3a380217d51b68a338382854bd6194e0 (patch)
tree87195bdcc8da26a523d472788d93b2c3dd94c42c
parent67b20a12d6016654663eb2726c2a095a6935593a (diff)
downloadvaadin-framework-ab9d395d3a380217d51b68a338382854bd6194e0.tar.gz
vaadin-framework-ab9d395d3a380217d51b68a338382854bd6194e0.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
-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 d7c1c54a2d..f683181857 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;
@@ -202,14 +203,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
@@ -547,14 +540,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;
}
});
@@ -858,6 +843,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) {
@@ -887,15 +888,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?)",
@@ -1269,7 +1284,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()) {