Browse Source

Avoid blocking in InMemoryWebSessionStore#changeSessionId

Closes gh-29212
pull/29969/head
rstoyanchev 3 years ago
parent
commit
b23316302d
  1. 19
      spring-web/src/main/java/org/springframework/web/server/session/InMemoryWebSessionStore.java

19
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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -229,12 +229,17 @@ public class InMemoryWebSessionStore implements WebSessionStore {
@Override @Override
public Mono<Void> changeSessionId() { public Mono<Void> changeSessionId() {
String currentId = this.id.get(); return Mono.<Void>defer(() -> {
InMemoryWebSessionStore.this.sessions.remove(currentId); String currentId = this.id.get();
String newId = String.valueOf(idGenerator.generateId()); InMemoryWebSessionStore.this.sessions.remove(currentId);
this.id.set(newId); String newId = String.valueOf(idGenerator.generateId());
InMemoryWebSessionStore.this.sessions.put(this.getId(), this); this.id.set(newId);
return Mono.empty(); InMemoryWebSessionStore.this.sessions.put(this.getId(), this);
return Mono.empty();
})
.subscribeOn(Schedulers.boundedElastic())
.publishOn(Schedulers.parallel())
.then();
} }
@Override @Override

Loading…
Cancel
Save