From b23316302d578694c6915d5fc9ef24b571110ffc Mon Sep 17 00:00:00 2001 From: rstoyanchev Date: Mon, 13 Feb 2023 18:38:54 +0000 Subject: [PATCH] Avoid blocking in InMemoryWebSessionStore#changeSessionId Closes gh-29212 --- .../session/InMemoryWebSessionStore.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/spring-web/src/main/java/org/springframework/web/server/session/InMemoryWebSessionStore.java b/spring-web/src/main/java/org/springframework/web/server/session/InMemoryWebSessionStore.java index 2e12a19a3ed..504ee546d32 100644 --- a/spring-web/src/main/java/org/springframework/web/server/session/InMemoryWebSessionStore.java +++ b/spring-web/src/main/java/org/springframework/web/server/session/InMemoryWebSessionStore.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -229,12 +229,17 @@ public class InMemoryWebSessionStore implements WebSessionStore { @Override public Mono changeSessionId() { - String currentId = this.id.get(); - InMemoryWebSessionStore.this.sessions.remove(currentId); - String newId = String.valueOf(idGenerator.generateId()); - this.id.set(newId); - InMemoryWebSessionStore.this.sessions.put(this.getId(), this); - return Mono.empty(); + return Mono.defer(() -> { + String currentId = this.id.get(); + InMemoryWebSessionStore.this.sessions.remove(currentId); + String newId = String.valueOf(idGenerator.generateId()); + this.id.set(newId); + InMemoryWebSessionStore.this.sessions.put(this.getId(), this); + return Mono.empty(); + }) + .subscribeOn(Schedulers.boundedElastic()) + .publishOn(Schedulers.parallel()) + .then(); } @Override