Skip to content

Commit de1ba79

Browse files
committed
Switch to non-blocking thread after WebSession creation
See gh-26958
1 parent ffbc537 commit de1ba79

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2021 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.
@@ -118,7 +118,8 @@ public Mono<WebSession> createWebSession() {
118118
this.expiredSessionChecker.checkIfNecessary(now);
119119

120120
return Mono.<WebSession>fromSupplier(() -> new InMemoryWebSession(now))
121-
.subscribeOn(Schedulers.boundedElastic());
121+
.subscribeOn(Schedulers.boundedElastic())
122+
.publishOn(Schedulers.parallel());
122123
}
123124

124125
@Override

spring-web/src/test/java/org/springframework/web/server/session/InMemoryWebSessionStoreTests.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2021 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.
@@ -22,9 +22,7 @@
2222
import java.util.Map;
2323
import java.util.stream.IntStream;
2424

25-
import org.junit.jupiter.api.Disabled;
2625
import org.junit.jupiter.api.Test;
27-
import reactor.core.publisher.Mono;
2826
import reactor.core.scheduler.Schedulers;
2927

3028
import org.springframework.beans.DirectFieldAccessor;
@@ -59,11 +57,10 @@ public void startsSessionImplicitly() {
5957
assertThat(session.isStarted()).isTrue();
6058
}
6159

62-
@Disabled // TODO: remove if/when Blockhound is enabled
63-
@Test // gh-24027
60+
@Test // gh-24027, gh-26958
6461
public void createSessionDoesNotBlock() {
65-
Mono.defer(() -> this.store.createWebSession())
66-
.subscribeOn(Schedulers.parallel())
62+
this.store.createWebSession()
63+
.doOnNext(session -> assertThat(Schedulers.isInNonBlockingThread()).isTrue())
6764
.block();
6865
}
6966

0 commit comments

Comments
 (0)