This is an automated email from the ASF dual-hosted git repository.

heneveld pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brooklyn-server.git

commit ae273935e30e0ffae0ad6ff141afc34e213e4fb1
Author: Alex Heneveld <[email protected]>
AuthorDate: Tue Sep 14 11:15:41 2021 +0100

    further fix for warning on http session retrieval race condition
---
 .../brooklyn/rest/util/MultiSessionAttributeAdapter.java   | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git 
a/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/util/MultiSessionAttributeAdapter.java
 
b/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/util/MultiSessionAttributeAdapter.java
index 0b1878e..2958a6e 100644
--- 
a/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/util/MultiSessionAttributeAdapter.java
+++ 
b/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/util/MultiSessionAttributeAdapter.java
@@ -154,7 +154,9 @@ public class MultiSessionAttributeAdapter {
             if(preferredSession!=null) {
                 // need to create a local session so the ID/session is 
registered with this ui module
                 if (r instanceof Request) {
-                // but synch on the session handler to avoid race conditions 
in the underlying code
+
+                // synch and own lookup to avoid the following warning
+
 //                2021-09-13T08:12:33,186Z - WARN  254 o.e.j.s.session 
[p1568796312-1154]
 //                java.lang.IllegalStateException: Session 
node0171nuqxrc6qsf1tbrmxztok6xc4 already in cache
 //                at 
org.eclipse.jetty.server.session.AbstractSessionCache.add(AbstractSessionCache.java:467)
 ~[!/:9.4.39.v20210325]
@@ -163,7 +165,15 @@ public class MultiSessionAttributeAdapter {
 //                at 
org.eclipse.jetty.server.Request.getSession(Request.java:1602) 
~[!/:9.4.39.v20210325]
 //                at 
org.apache.brooklyn.rest.util.MultiSessionAttributeAdapter.of(MultiSessionAttributeAdapter.java:155)
 ~[!/:1.1.0-SNAPSHOT]
                     synchronized (((Request)r).getSessionHandler()) {
-                        localSession = r.getSession();
+                        try {
+                            String id = ((Request) 
r).getSessionHandler().getSessionIdManager().newSessionId(r, 
System.currentTimeMillis());
+                            localSession = ((Request) 
r).getSessionHandler().getSession(id);
+                        } catch (Exception e) {
+                            log.debug("Unable to retrieve session via safe 
override, falling back to default: "+e);
+                        }
+                        if (localSession==null) {
+                            localSession = r.getSession();
+                        }
                     }
                 } else {
                     localSession = r.getSession();

Reply via email to