Skip to content

Commit 033548a

Browse files
OlgaMaciaszekrstoyanchev
authored andcommitted
Remove default blockTimeout on interface clients
See gh-30403
1 parent e416dfd commit 033548a

File tree

6 files changed

+33
-15
lines changed

6 files changed

+33
-15
lines changed

framework-docs/modules/ROOT/pages/integration/rest-clients.adoc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,11 @@ Annotated, HTTP exchange methods support the following return values:
497497
TIP: You can also use any other async or reactive types registered in the
498498
`ReactiveAdapterRegistry`.
499499

500+
TIP: For non-reactive types, blocking from a reactive publisher is performed
501+
under the hood by the framework. By default, it is done without a timeout.
502+
You can set a timeout for blocking by calling `blockTimeout(Duration blockTimeout)`
503+
on `HttpServiceProxyFactory.Builder`.
504+
500505

501506
[[rest-http-interface-exceptions]]
502507
=== Exception Handling

framework-docs/modules/ROOT/pages/rsocket.adoc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,3 +1063,8 @@ method parameters:
10631063
Annotated, RSocket exchange methods support return values that are concrete value(s), or
10641064
any producer of value(s) that can be adapted to a Reactive Streams `Publisher` via
10651065
`ReactiveAdapterRegistry`.
1066+
1067+
TIP: For non-reactive types, blocking from a reactive publisher is performed
1068+
under the hood by the framework. By default, it is done without a timeout.
1069+
You can set a timeout for blocking by calling `blockTimeout(Duration blockTimeout)`
1070+
on `RSocketServiceProxyFactory.Builder`.

spring-messaging/src/main/java/org/springframework/messaging/rsocket/service/RSocketServiceMethod.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ final class RSocketServiceMethod {
6767
RSocketServiceMethod(
6868
Method method, Class<?> containingClass, List<RSocketServiceArgumentResolver> argumentResolvers,
6969
RSocketRequester rsocketRequester, @Nullable StringValueResolver embeddedValueResolver,
70-
ReactiveAdapterRegistry reactiveRegistry, Duration blockTimeout) {
70+
ReactiveAdapterRegistry reactiveRegistry, @Nullable Duration blockTimeout) {
7171

7272
this.method = method;
7373
this.parameters = initMethodParameters(method);
@@ -125,7 +125,7 @@ private static String initRoute(
125125

126126
private static Function<RSocketRequestValues, Object> initResponseFunction(
127127
RSocketRequester requester, Method method,
128-
ReactiveAdapterRegistry reactiveRegistry, Duration blockTimeout) {
128+
ReactiveAdapterRegistry reactiveRegistry, @Nullable Duration blockTimeout) {
129129

130130
MethodParameter returnParam = new MethodParameter(method, -1);
131131
Class<?> returnType = returnParam.getParameterType();
@@ -164,8 +164,10 @@ else if (reactiveAdapter == null) {
164164
return reactiveAdapter.fromPublisher(responsePublisher);
165165
}
166166
return (blockForOptional ?
167-
((Mono<?>) responsePublisher).blockOptional(blockTimeout) :
168-
((Mono<?>) responsePublisher).block(blockTimeout));
167+
(blockTimeout != null ? ((Mono<?>) responsePublisher).blockOptional(blockTimeout) :
168+
((Mono<?>) responsePublisher).blockOptional()) :
169+
(blockTimeout != null ? ((Mono<?>) responsePublisher).block(blockTimeout) :
170+
((Mono<?>) responsePublisher).block()));
169171
});
170172
}
171173

spring-messaging/src/main/java/org/springframework/messaging/rsocket/service/RSocketServiceProxyFactory.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,14 @@ public final class RSocketServiceProxyFactory {
5959

6060
private final ReactiveAdapterRegistry reactiveAdapterRegistry;
6161

62+
@Nullable
6263
private final Duration blockTimeout;
6364

6465

6566
private RSocketServiceProxyFactory(
6667
RSocketRequester rsocketRequester, List<RSocketServiceArgumentResolver> argumentResolvers,
6768
@Nullable StringValueResolver embeddedValueResolver,
68-
ReactiveAdapterRegistry reactiveAdapterRegistry, Duration blockTimeout) {
69+
ReactiveAdapterRegistry reactiveAdapterRegistry, @Nullable Duration blockTimeout) {
6970

7071
this.rsocketRequester = rsocketRequester;
7172
this.argumentResolvers = argumentResolvers;
@@ -139,7 +140,7 @@ public static final class Builder {
139140
private ReactiveAdapterRegistry reactiveAdapterRegistry = ReactiveAdapterRegistry.getSharedInstance();
140141

141142
@Nullable
142-
private Duration blockTimeout = Duration.ofSeconds(5);
143+
private Duration blockTimeout;
143144

144145
private Builder() {
145146
}
@@ -189,7 +190,8 @@ public Builder reactiveAdapterRegistry(ReactiveAdapterRegistry registry) {
189190
/**
190191
* Configure how long to wait for a response for an HTTP service method
191192
* with a synchronous (blocking) method signature.
192-
* <p>By default this is 5 seconds.
193+
* <p>By default this is {@code null},
194+
* in which case means blocking on publishers is done without a timeout.
193195
* @param blockTimeout the timeout value
194196
* @return this same builder instance
195197
*/
@@ -207,7 +209,7 @@ public RSocketServiceProxyFactory build() {
207209
return new RSocketServiceProxyFactory(
208210
this.rsocketRequester, initArgumentResolvers(),
209211
this.embeddedValueResolver, this.reactiveAdapterRegistry,
210-
(this.blockTimeout != null ? this.blockTimeout : Duration.ofSeconds(5)));
212+
this.blockTimeout);
211213
}
212214

213215
private List<RSocketServiceArgumentResolver> initArgumentResolvers() {

spring-web/src/main/java/org/springframework/web/service/invoker/HttpServiceMethod.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ final class HttpServiceMethod {
7171
HttpServiceMethod(
7272
Method method, Class<?> containingClass, List<HttpServiceArgumentResolver> argumentResolvers,
7373
HttpClientAdapter client, @Nullable StringValueResolver embeddedValueResolver,
74-
ReactiveAdapterRegistry reactiveRegistry, Duration blockTimeout) {
74+
ReactiveAdapterRegistry reactiveRegistry, @Nullable Duration blockTimeout) {
7575

7676
this.method = method;
7777
this.parameters = initMethodParameters(method);
@@ -275,7 +275,7 @@ private static List<MediaType> initAccept(@Nullable HttpExchange typeAnnot, Http
275275
private record ResponseFunction(
276276
Function<HttpRequestValues, Publisher<?>> responseFunction,
277277
@Nullable ReactiveAdapter returnTypeAdapter,
278-
boolean blockForOptional, Duration blockTimeout) {
278+
boolean blockForOptional, @Nullable Duration blockTimeout) {
279279

280280
private ResponseFunction(
281281
Function<HttpRequestValues, Publisher<?>> responseFunction,
@@ -298,8 +298,10 @@ public Object execute(HttpRequestValues requestValues) {
298298
}
299299

300300
return (this.blockForOptional ?
301-
((Mono<?>) responsePublisher).blockOptional(this.blockTimeout) :
302-
((Mono<?>) responsePublisher).block(this.blockTimeout));
301+
(this.blockTimeout != null ? ((Mono<?>) responsePublisher).blockOptional(this.blockTimeout) :
302+
((Mono<?>) responsePublisher).blockOptional()) :
303+
(this.blockTimeout != null ? ((Mono<?>) responsePublisher).block(this.blockTimeout) :
304+
((Mono<?>) responsePublisher).block()));
303305
}
304306

305307

spring-web/src/main/java/org/springframework/web/service/invoker/HttpServiceProxyFactory.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,14 @@ public final class HttpServiceProxyFactory {
6666

6767
private final ReactiveAdapterRegistry reactiveAdapterRegistry;
6868

69+
@Nullable
6970
private final Duration blockTimeout;
7071

7172

7273
private HttpServiceProxyFactory(
7374
HttpClientAdapter clientAdapter, List<HttpServiceArgumentResolver> argumentResolvers,
7475
@Nullable StringValueResolver embeddedValueResolver,
75-
ReactiveAdapterRegistry reactiveAdapterRegistry, Duration blockTimeout) {
76+
ReactiveAdapterRegistry reactiveAdapterRegistry, @Nullable Duration blockTimeout) {
7677

7778
this.clientAdapter = clientAdapter;
7879
this.argumentResolvers = argumentResolvers;
@@ -208,7 +209,8 @@ public Builder reactiveAdapterRegistry(ReactiveAdapterRegistry registry) {
208209
/**
209210
* Configure how long to wait for a response for an HTTP service method
210211
* with a synchronous (blocking) method signature.
211-
* <p>By default this is 5 seconds.
212+
* <p>By default this is {@code null},
213+
* in which case means blocking on publishers is done without a timeout.
212214
* @param blockTimeout the timeout value
213215
* @return this same builder instance
214216
*/
@@ -226,7 +228,7 @@ public HttpServiceProxyFactory build() {
226228
return new HttpServiceProxyFactory(
227229
this.clientAdapter, initArgumentResolvers(),
228230
this.embeddedValueResolver, this.reactiveAdapterRegistry,
229-
(this.blockTimeout != null ? this.blockTimeout : Duration.ofSeconds(5)));
231+
this.blockTimeout);
230232
}
231233

232234
private List<HttpServiceArgumentResolver> initArgumentResolvers() {

0 commit comments

Comments
 (0)