aboutsummaryrefslogtreecommitdiffstats
path: root/server/src/main
diff options
context:
space:
mode:
authorTatu Lund <tatu@vaadin.com>2020-06-30 11:54:55 +0300
committerGitHub <noreply@github.com>2020-06-30 11:54:55 +0300
commitbafced6af34e398d52ef466b5752b34a8fd3684a (patch)
treec793113e7fc22a249cfb7836d38fab7f183f4a60 /server/src/main
parent797b49372f3198495cb4e331cab85e040afd352e (diff)
downloadvaadin-framework-bafced6af34e398d52ef466b5752b34a8fd3684a.tar.gz
vaadin-framework-bafced6af34e398d52ef466b5752b34a8fd3684a.zip
Clear thread local instances on connection lost in push handler (#12042)
Adopted from https://github.com/vaadin/flow/pull/8567
Diffstat (limited to 'server/src/main')
-rw-r--r--server/src/main/java/com/vaadin/server/communication/PushHandler.java32
1 files changed, 25 insertions, 7 deletions
diff --git a/server/src/main/java/com/vaadin/server/communication/PushHandler.java b/server/src/main/java/com/vaadin/server/communication/PushHandler.java
index 030d4323ef..77dd1b9b57 100644
--- a/server/src/main/java/com/vaadin/server/communication/PushHandler.java
+++ b/server/src/main/java/com/vaadin/server/communication/PushHandler.java
@@ -44,6 +44,7 @@ import com.vaadin.shared.ApplicationConstants;
import com.vaadin.shared.JsonConstants;
import com.vaadin.shared.communication.PushMode;
import com.vaadin.ui.UI;
+import com.vaadin.util.CurrentInstance;
import elemental.json.JsonException;
@@ -316,13 +317,29 @@ public class PushHandler {
}
void connectionLost(AtmosphereResourceEvent event) {
+ VaadinSession session = null;
+ try {
+ session = handleConnectionLost(event);
+ } finally {
+ if (session != null) {
+ session.access(new Runnable() {
+ @Override
+ public void run() {
+ CurrentInstance.clearAll();
+ }
+ });
+ }
+ }
+ }
+
+ private VaadinSession handleConnectionLost(AtmosphereResourceEvent event) {
// We don't want to use callWithUi here, as it assumes there's a client
// request active and does requestStart and requestEnd among other
// things.
if (event == null) {
getLogger().log(Level.SEVERE,
"Could not get event. This should never happen.");
- return;
+ return null;
}
AtmosphereResource resource = event.getResource();
@@ -330,7 +347,7 @@ public class PushHandler {
if (resource == null) {
getLogger().log(Level.SEVERE,
"Could not get resource. This should never happen.");
- return;
+ return null;
}
VaadinServletRequest vaadinRequest = new VaadinServletRequest(
@@ -342,7 +359,7 @@ public class PushHandler {
} catch (ServiceException e) {
getLogger().log(Level.SEVERE,
"Could not get session. This should never happen", e);
- return;
+ return null;
} catch (SessionExpiredException e) {
// This happens at least if the server is restarted without
// preserving the session. After restart the client reconnects, gets
@@ -351,7 +368,7 @@ public class PushHandler {
getLogger().log(Level.FINER,
"Session expired before push disconnect event was received",
e);
- return;
+ return session;
}
UI ui = null;
@@ -375,13 +392,13 @@ public class PushHandler {
getLogger().log(Level.FINE,
"Could not get UI. This should never happen,"
+ " except when reloading in Firefox and Chrome -"
- + " see http://dev.vaadin.com/ticket/14251.");
- return;
+ + " see https://github.com/vaadin/framework/issues/5449.");
+ return session;
} else {
getLogger().log(Level.INFO,
"No UI was found based on data in the request,"
+ " but a slower lookup based on the AtmosphereResource succeeded."
- + " See http://dev.vaadin.com/ticket/14251 for more details.");
+ + " See https://github.com/vaadin/framework/issues/5449 for more details.");
}
}
@@ -426,6 +443,7 @@ public class PushHandler {
// can't call ErrorHandler, we (hopefully) don't have a lock
}
}
+ return session;
}
private static UI findUiUsingResource(AtmosphereResource resource,