spring-cloud-gateway: reactor.netty.http.client.PrematureCloseException: Connection prematurely closed BEFORE response,springboot2.1.6
springboot2.1.6.RELEASE and Spring Cloud Greenwich.SR1

application.yml
spring: application: name: gateway-service cloud: gateway: default-filters: - StripPrefix=1 routes: - id: provider_api_route uri: lb://provider-service predicates: - Path=/web/** discovery: locator: enabled: true consul: enabled: true discovery: instanceId: ${spring.application.name}😒{vcap.application.instance_id:${spring.application.instance_id:${random.value}}} #prefer-ip-address: true retry: initial-interval: 10 multiplier: 1 max-interval: 30000 max-attempts: 15
my pom.xml
` <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.6.RELEASE</version> <relativePath/> </parent> <groupId>com.example</groupId> <artifactId>demo</artifactId> <version>0.0.1-SNAPSHOT</version> <name>demo</name> <description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Greenwich.SR1</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-consul-discovery</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
`About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 24 (11 by maintainers)
@creaton60 have you tried to set the maxIdleTime property?
AFAIR by default, it is NULL so your connection will be waiting forever without closing it on the gateway and it may be closed on server site.
https://blog.csdn.net/rickiyeat/article/details/107900585
@Ziemowit Thank you very mutch. It solved my problem. The
Spring Cloud Gatewayprojectspring.cloud.gateway.httpclient.pool.max-idle-timedefalut value was null (there is no max). my proxy target server was tomcat,server.connection-timeoutdefault was20000ms. My server was set to100ms,100mswas to short, it cause manyPrematureCloseException.My solution:
Notice:
spring.cloud.gateway.httpclient.pool.max-idle-timemust be less than orserver.connection-timeouthttps://github.com/reactor/reactor-netty/issues/1092
Please open a new issue and provide the stack trace
Closed via 069f24d568678d3698bd9ac3a8ea7d8a1c0f1943
We need step by step instructions and maybe a project that recreates the problem (not pasted code).
Please, don’t use screenshots.
How do we recreate the problem?