@@ -103,7 +103,7 @@ public void stop() {
103103 }
104104
105105 @ Override
106- public Session createSession (HttpServerExchange serverExchange , SessionConfig sessionCookieConfig ) {
106+ public Session createSession (final HttpServerExchange serverExchange , final SessionConfig config ) {
107107 if (evictionQueue != null ) {
108108 while (sessions .size () >= maxSize && !evictionQueue .isEmpty ()) {
109109 String key = evictionQueue .poll ();
@@ -114,10 +114,10 @@ public Session createSession(HttpServerExchange serverExchange, SessionConfig se
114114 }
115115 }
116116 }
117- if (sessionCookieConfig == null ) {
117+ if (config == null ) {
118118 throw UndertowMessages .MESSAGES .couldNotFindSessionCookieConfig ();
119119 }
120- String sessionID = sessionCookieConfig .findSessionId (serverExchange );
120+ String sessionID = config .findSessionId (serverExchange );
121121 int count = 0 ;
122122 while (sessionID == null ) {
123123 sessionID = sessionIdGenerator .createSessionId ();
@@ -136,10 +136,10 @@ public Session createSession(HttpServerExchange serverExchange, SessionConfig se
136136 } else {
137137 evictionToken = null ;
138138 }
139- final ConvergedSessionImpl session = new ConvergedSessionImpl (this , sessionID , sessionCookieConfig , serverExchange .getIoThread (), serverExchange .getConnection ().getWorker (), evictionToken );
139+ final ConvergedSessionImpl session = new ConvergedSessionImpl (this , sessionID , config , serverExchange .getIoThread (), serverExchange .getConnection ().getWorker (), evictionToken );
140140 ConvergedInMemorySession im = new ConvergedInMemorySession (session , defaultSessionTimeout );
141141 sessions .put (sessionID , im );
142- sessionCookieConfig .setSessionId (serverExchange , session .getId ());
142+ config .setSessionId (serverExchange , session .getId ());
143143 im .lastAccessed = System .currentTimeMillis ();
144144 session .bumpTimeout ();
145145 sessionListeners .sessionCreated (session , serverExchange );
@@ -158,7 +158,7 @@ public void addConvergedSessionDeletegateToSession(SessionConfig sessionCookieCo
158158 }
159159
160160 @ Override
161- public Session getSession (HttpServerExchange serverExchange , SessionConfig sessionCookieConfig ) {
161+ public Session getSession (final HttpServerExchange serverExchange , final SessionConfig sessionCookieConfig ) {
162162 String sessionId = sessionCookieConfig .findSessionId (serverExchange );
163163 return getSession (sessionId );
164164 }
@@ -182,12 +182,12 @@ public void registerSessionListener(SessionListener listener) {
182182 }
183183
184184 @ Override
185- public void removeSessionListener (SessionListener listener ) {
185+ public synchronized void removeSessionListener (final SessionListener listener ) {
186186 sessionListeners .removeSessionListener (listener );
187187 }
188188
189189 @ Override
190- public void setDefaultSessionTimeout (int timeout ) {
190+ public void setDefaultSessionTimeout (final int timeout ) {
191191 defaultSessionTimeout = timeout ;
192192 }
193193
@@ -206,6 +206,23 @@ public Set<String> getAllSessions() {
206206 return new HashSet <>(sessions .keySet ());
207207 }
208208
209+ @ Override
210+ public boolean equals (Object object ) {
211+ if (!(object instanceof SessionManager )) return false ;
212+ SessionManager manager = (SessionManager ) object ;
213+ return this .deploymentName .equals (manager .getDeploymentName ());
214+ }
215+
216+ @ Override
217+ public int hashCode () {
218+ return this .deploymentName .hashCode ();
219+ }
220+
221+ @ Override
222+ public String toString () {
223+ return this .deploymentName ;
224+ }
225+
209226 /**
210227 * session implementation for the in memory session manager
211228 */
@@ -235,6 +252,7 @@ private static AtomicReferenceFieldUpdater<ConvergedSessionImpl, Object> createT
235252 private volatile Object evictionToken ;
236253 private final SessionConfig sessionCookieConfig ;
237254 private volatile long expireTime = -1 ;
255+ private volatile boolean invalidationStarted = false ;
238256
239257 final XnioExecutor executor ;
240258 final XnioWorker worker ;
@@ -268,9 +286,13 @@ private ConvergedSessionImpl(ConvergedInMemorySessionManager sessionManager, fin
268286 }
269287
270288 synchronized void bumpTimeout () {
289+ if (invalidationStarted ) {
290+ return ;
291+ }
292+
271293 final int maxInactiveInterval = getMaxInactiveInterval ();
272294 if (maxInactiveInterval > 0 ) {
273- long newExpireTime = System .currentTimeMillis () + (maxInactiveInterval * 1000 );
295+ long newExpireTime = System .currentTimeMillis () + (maxInactiveInterval * 1000L );
274296 if (timerCancelKey != null && (newExpireTime < expireTime )) {
275297 // We have to re-schedule as the new maxInactiveInterval is lower than the old one
276298 if (!timerCancelKey .remove ()) {
@@ -283,7 +305,7 @@ synchronized void bumpTimeout() {
283305 //+1 second, to make sure that the time has actually expired
284306 //we don't re-schedule every time, as it is expensive
285307 //instead when it expires we check if the timeout has been bumped, and if so we re-schedule
286- timerCancelKey = executor .executeAfter (cancelTask , (maxInactiveInterval * 1000 ) + 1 , TimeUnit .MILLISECONDS );
308+ timerCancelKey = executor .executeAfter (cancelTask , (maxInactiveInterval * 1000L ) + 1 , TimeUnit .MILLISECONDS );
287309 }
288310 }
289311 if (evictionToken != null ) {
@@ -405,22 +427,27 @@ public void invalidate(final HttpServerExchange exchange) {
405427 invalidate (exchange , SessionListener .SessionDestroyedReason .INVALIDATED );
406428 }
407429
408- synchronized void invalidate (final HttpServerExchange exchange , SessionListener .SessionDestroyedReason reason ) {
409- if (timerCancelKey != null ) {
410- timerCancelKey .remove ();
411- }
412- ConvergedInMemorySession sess = sessionManager .sessions .get (sessionId );
413- if (sess == null ) {
414- if (reason == SessionListener .SessionDestroyedReason .INVALIDATED ) {
415- throw UndertowMessages .MESSAGES .sessionAlreadyInvalidated ();
430+ void invalidate (final HttpServerExchange exchange , SessionListener .SessionDestroyedReason reason ) {
431+ synchronized (ConvergedSessionImpl .this ) {
432+ if (timerCancelKey != null ) {
433+ timerCancelKey .remove ();
416434 }
417- return ;
435+ ConvergedInMemorySession sess = sessionManager .sessions .get (sessionId );
436+ if (sess == null ) {
437+ if (reason == SessionListener .SessionDestroyedReason .INVALIDATED ) {
438+ throw UndertowMessages .MESSAGES .sessionAlreadyInvalidated ();
439+ }
440+ return ;
441+ }
442+ invalidationStarted = true ;
418443 }
419- sessionManager .sessionListeners .sessionDestroyed (sess .session , exchange , reason );
444+ sessionManager .sessionListeners .sessionDestroyed (this , exchange , reason );
445+
420446 sessionManager .sessions .remove (sessionId );
421447 if (exchange != null ) {
422448 sessionCookieConfig .clearSession (exchange , this .getId ());
423449 }
450+
424451 }
425452
426453 @ Override
0 commit comments