Skip to content

Commit

Permalink
Avoid blocking in InMemoryWebSessionStore#changeSessionId
Browse files Browse the repository at this point in the history
  • Loading branch information
rstoyanchev committed Feb 13, 2023
1 parent dc843ad commit b233163
Showing 1 changed file with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -229,12 +229,17 @@ public boolean isStarted() {

@Override
public Mono<Void> 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.<Void>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
Expand Down

0 comments on commit b233163

Please sign in to comment.