Skip to content

Commit b233163

Browse files
committedFeb 13, 2023
Avoid blocking in InMemoryWebSessionStore#changeSessionId
Closes spring-projectsgh-29212
1 parent dc843ad commit b233163

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed
 

‎spring-web/src/main/java/org/springframework/web/server/session/InMemoryWebSessionStore.java

+12-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -229,12 +229,17 @@ public boolean isStarted() {
229229

230230
@Override
231231
public Mono<Void> changeSessionId() {
232-
String currentId = this.id.get();
233-
InMemoryWebSessionStore.this.sessions.remove(currentId);
234-
String newId = String.valueOf(idGenerator.generateId());
235-
this.id.set(newId);
236-
InMemoryWebSessionStore.this.sessions.put(this.getId(), this);
237-
return Mono.empty();
232+
return Mono.<Void>defer(() -> {
233+
String currentId = this.id.get();
234+
InMemoryWebSessionStore.this.sessions.remove(currentId);
235+
String newId = String.valueOf(idGenerator.generateId());
236+
this.id.set(newId);
237+
InMemoryWebSessionStore.this.sessions.put(this.getId(), this);
238+
return Mono.empty();
239+
})
240+
.subscribeOn(Schedulers.boundedElastic())
241+
.publishOn(Schedulers.parallel())
242+
.then();
238243
}
239244

240245
@Override

0 commit comments

Comments
 (0)
Please sign in to comment.