Reputation: 21
I'm using Spring webclient to connect to the netty webflux server.
I'm receiving this error after 20-30 minutes when consumer is idle.
Is that because connection is closed from server-side or the problem is in client-side?
reactor.netty.http.client.PrematureCloseException:
Connection prematurely closed DURING response
Suppressed:
reactor.core.publisher.FluxOnAssembly$OnAssemblyException:
Error has been observed at the following site(s):
|_ checkpoint ? Body from GET https://*** [DefaultClientResponse]
Upvotes: 2
Views: 8740
Reputation: 2995
This is generally caused by the server side closing the idle connection.
On the client side, you can configure how long an idle connection is used for by invoking the maxIdleTime
method on the ConnectionProvider
builder. Example taken from Connection Pool Reference Docs.
ConnectionProvider.builder("custom")
.maxConnections(50)
.maxIdleTime(Duration.ofSeconds(20))
.maxLifeTime(Duration.ofSeconds(60))
.build()
maxIdleTime - The maximum time (resolution: ms) that this connection stays idle in the connection pool. By default, maxIdleTime is not specified.
maxLifeTime - The maximum time (resolution: ms) that this connection stays alive. By default, maxLifeTime is not specified.
This note from the reference docs is particularly key for the issue you are seeing with the target server closing the connection before the client.
When you configure maxIdleTime, you should consider the idle timeout configuration on the target server. Choose a configuration that is equal to or less than the one on the target server. By doing so, you can reduce the I/O issues caused by a connection closed by the target server.
Upvotes: 1