Skip to content
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

Switch back to parallel thread after WebSession id is generated #26958

Closed
jzheaux opened this issue May 19, 2021 · 2 comments
Closed

Switch back to parallel thread after WebSession id is generated #26958

jzheaux opened this issue May 19, 2021 · 2 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Milestone

Comments

@jzheaux
Copy link
Contributor

jzheaux commented May 19, 2021

It would be nice if there were a way to request the session without creating an instance of one, similar conceptually to HttpServletRequest#getSession(false).

Whenever the session is requested, say like so:

exchange.getSession().filter((session) -> {
    if (session.getAttribute("attribute") != null) {
        // ...
    }
})
// ...

subscription will cause an InMemoryWebSession to be constructed. Since this is a blocking operation, it would be nice to avoid it when not needed.

If instead an application could do:

exchange.getSessionOrEmpty().filter((session) -> {
    if (session.getAttribute("attribute") != null) {
        // ...
    }
})

then the predicate would not be invoked at all and construction of InMemoryWebSession would be avoided.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label May 19, 2021
@rstoyanchev rstoyanchev self-assigned this May 19, 2021
@rstoyanchev rstoyanchev added in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels May 19, 2021
@rstoyanchev rstoyanchev added this to the 5.3.8 milestone May 19, 2021
@rstoyanchev rstoyanchev changed the title Add getSessionOrEmpty Add option to get WebSession instance only if a session exists May 19, 2021
MaxBartkov added a commit to MaxBartkov/spring-framework that referenced this issue May 21, 2021
@MaxBartkov
Copy link

Created merge request: #26965

@rstoyanchev
Copy link
Contributor

Closing for now with the change to switch back to a parallel thread. That should address the specific side effects reported in spring-projects/spring-security#9200. We can explore a more optimal, longer term solution for 6.0, such as new methods on WebSession and ServerWebExchange or perhaps a non-blocking id generator if that's even feasible.

@rstoyanchev rstoyanchev changed the title Add option to get WebSession instance only if a session exists Switch back to parallel thread after WebSession id is generated Jun 8, 2021
lxbzmy pushed a commit to lxbzmy/spring-framework that referenced this issue Mar 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants