javaspringspring-bootspring-session

How can I increase the in memory session store to maximum


Please note this is not about concurrent user session. This is about the total sessions can be stored in the in memory.

Here is the log :

java.lang.IllegalStateException: Max sessions limit reached: 10000
    at org.springframework.web.server.session.InMemoryWebSessionStore$InMemoryWebSession.checkMaxSessionsLimit(InMemoryWebSessionStore.java:276)
    at org.springframework.web.server.session.InMemoryWebSessionStore$InMemoryWebSession.save(InMemoryWebSessionStore.java:251)
    at org.springframework.web.server.session.DefaultWebSessionManager.save(DefaultWebSessionManager.java:123)
    at org.springframework.web.server.session.DefaultWebSessionManager.lambda$null$0(DefaultWebSessionManager.java:88)
    at reactor.core.publisher.FluxMapFuseable$MapFuseableSubscriber.onNext(FluxMapFuseable.java:113)
    at reactor.core.publisher.FluxIterable$IterableSubscription.slowPath(FluxIterable.java:272)
    at reactor.core.publisher.FluxIterable$IterableSubscription.request(FluxIterable.java:230)
    at reactor.core.publisher.FluxMapFuseable$MapFuseableSubscriber.request(FluxMapFuseable.java:171)
    at reactor.core.publisher.FluxConcatMap$ConcatMapImmediate.onSubscribe(FluxConcatMap.java:236)

You can find the spring doc here https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/server/session/InMemoryWebSessionStore.html

I created a bean like below but not sure about this :

    @Bean
    public InMemoryWebSessionStore inMemoryWebSessionStore() {
        InMemoryWebSessionStore inMemoryWebSessionStore = new InMemoryWebSessionStore();
        inMemoryWebSessionStore.setMaxSessions(-1);
        return inMemoryWebSessionStore;
    }


Solution

  • I finally found a solution that worked for me.

    @Bean
    public WebSessionManager webSessionManager () {
        DefaultWebSessionManager webSessionManager = new DefaultWebSessionManager();
        InMemoryWebSessionStore inMemoryWebSessionStore = new InMemoryWebSessionStore();
        inMemoryWebSessionStore.setMaxSessions(2147483647); //2147483647 - MAX_VALUE of Integer
        webSessionManager.setSessionStore(inMemoryWebSessionStore);
        return webSessionManager;
    }