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.

Comment From: MaxBartkov

Created merge request: https://github.com/spring-projects/spring-framework/pull/26965

Comment From: rstoyanchev

Closing for now with the change to switch back to a parallel thread. That should address the specific side effects reported in https://github.com/spring-projects/spring-security/issues/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.