-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Undertow - Session context lifecycle events should be observable from session scoped beans #46364
Draft
manovotn
wants to merge
2
commits into
quarkusio:main
Choose a base branch
from
manovotn:undertowSessionContextFix
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+42
−3
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
...ployment/src/test/java/io/quarkus/undertow/test/sessioncontext/SessionScopedObserver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package io.quarkus.undertow.test.sessioncontext; | ||
|
||
import jakarta.enterprise.context.BeforeDestroyed; | ||
import jakarta.enterprise.context.Initialized; | ||
import jakarta.enterprise.context.SessionScoped; | ||
import jakarta.enterprise.event.Observes; | ||
|
||
@SessionScoped | ||
public class SessionScopedObserver { | ||
|
||
static int timesInitObserved = 0; | ||
static int timesBeforeDestroyedObserved = 0; | ||
|
||
public void observeInit(@Observes @Initialized(SessionScoped.class) Object event) { | ||
timesInitObserved++; | ||
} | ||
|
||
public void observeBeforeDestroyed(@Observes @BeforeDestroyed(SessionScoped.class) Object event) { | ||
timesBeforeDestroyedObserved++; | ||
} | ||
|
||
public static void resetState() { | ||
timesInitObserved = 0; | ||
timesBeforeDestroyedObserved = 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we need a thread local because at this point the
ServletRequestContext.requireCurrent().getServletRequest()).getSession(true)
returnsnull
or a different session?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A different session - with
true
it always creates a new one.Plus if you try the same invocation with
false
(to see the session for which you just called session created callback), you will getnull
at this point 🤷So we need some way to remember that we already created a session - at least that was my thinking.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's weird, it should only create a new one if it does not exist, right? And given that it's called from
jakarta.servlet.http.HttpSessionListener.sessionCreated(HttpSessionEvent)
I would expect the session to exist...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is pretty much my yesterday thinking in a nutshell :)
Somehow, it ends up creating new session anyway.
You can debug this all the way to
io.undertow.servlet.spec.ServletContextImpl#getSession
where undertow tries to retrieve existing session first but I didn't manage to understand why it doesn't find it or whether it is right or wrong.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we can crack this with our knowledge of servlet/undertow...
I've sent an email question to @fl4via who should hopefully know more about Undertow and how it should behave it this case.