A large number of CLOSE_WAIT occurs by using zuul


A large number of CLOSE_WAIT occurs by using zuul



when i use springcloud zuul, there is a large number of TCP CLOSE_WAIT status occurs,can anyone knows why its happens?



here is my zuul configuration



parent pom


<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
<relativePath />
</parent>



pom.xml


<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-zuul</artifactId>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Edgware.SR2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>



application.properties


server.port=8081
spring.application.name=zuul-server-test
eureka.instance.preferIpAddress=true
eureka.instance.instance-id=${spring.cloud.client.ipAddress}:${server.port}
eureka.instance.leaseRenewalIntervalInSeconds=5
eureka.instance.leaseExpirationDurationInSeconds=10
eureka.client.serviceUrl.defaultZone=http://127.0.0.1:8080/eureka/

zuul.add-host-header=true
zuul.sensitive-headers=

hystrix.command.default.execution.timeout.enable=true
hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=60000
zuul.host.connect-timeout-millis=60000
zuul.host.socket-timeout-milllis=60000

ribbon.eureka.enabled=true
ribbon.ReadTimeout=60000
ribbon.ConnectTimeout=30000
ribbon.MaxAutoRetries=0
ribbon.MaxAutoRetriesNextServer=1
ribbon.OkToRetryOnAllOperations=false
ribbon.httpclient.enabled=false
ribbon.okhttp.enabled=true

zuul.routes.hello.path=/hello/**
zuul.routes.hello.sensitiveHeaders=
zuul.routes.hello.service-id=hello-server



java


@SpringBootApplication
@EnableDiscoveryClient
@EnableZuulProxy
public class DevcloudZuulApplication {
public static void main(String args) {
SpringApplication.run(DevcloudZuulApplication.class, args);
}
}



when i visit http://localhost:8081/hello/index.html, tcp links created, port 8082 is the hello-server


tcp 0 0 ::ffff:192.168.120.20:8082 ::ffff:192.168.120.20:21505 ESTABLISHED 47968/java
tcp 0 0 ::ffff:192.168.120.20:21505 ::ffff:192.168.120.20:8082 ESTABLISHED 132689/java
tcp 0 0 ::ffff:192.168.120.20:8082 ::ffff:192.168.120.20:21510 ESTABLISHED 47968/java
tcp 0 0 ::ffff:192.168.120.20:21510 ::ffff:192.168.120.20:8082 ESTABLISHED 132689/java
tcp 0 0 ::ffff:192.168.120.20:8082 ::ffff:192.168.120.20:21504 ESTABLISHED 47968/java
tcp 0 0 ::ffff:192.168.120.20:21504 ::ffff:192.168.120.20:8082 ESTABLISHED 132689/java



then it changes


tcp 0 0 ::ffff:192.168.120.20:8082 ::ffff:192.168.120.20:21505 FIN_WAIT2 -
tcp 1 0 ::ffff:192.168.120.20:21505 ::ffff:192.168.120.20:8082 CLOSE_WAIT 132689/java
tcp 0 0 ::ffff:192.168.120.20:8082 ::ffff:192.168.120.20:21510 FIN_WAIT2 -
tcp 0 0 ::ffff:192.168.120.20:21510 ::ffff:192.168.120.20:8082 CLOSE_WAIT 132689/java
tcp 0 0 ::ffff:192.168.120.20:8082 ::ffff:192.168.120.20:21504 FIN_WAIT2 -
tcp 1 0 ::ffff:192.168.120.20:21504 ::ffff:192.168.120.20:8082 CLOSE_WAIT 132689/java



at last,


tcp 1 0 ::ffff:192.168.120.20:21505 ::ffff:192.168.120.20:8082 CLOSE_WAIT 132689/java
tcp 1 0 ::ffff:192.168.120.20:21504 ::ffff:192.168.120.20:8082 CLOSE_WAIT 132689/java
tcp 1 0 ::ffff:192.168.120.20:21510 ::ffff:192.168.120.20:8082 CLOSE_WAIT 132689/java



and this status will continue through hours.




1 Answer
1



CLOSE_WAIT described here: TCP connection status


CLOSE_WAIT



This endpoint has received a close request from the remote endpoint and this TCP is now waiting for a connection termination request from the local application.



Ribbon uses a connection pool to send request to upstream. Every time, it releases connection instead of close it to avoid overhead of establishing new connection.



The connections in pool has alive time by configuring ribbon.PoolKeepAliveTime which default value is 15 * 60 seconds.


ribbon.PoolKeepAliveTime


public class DefaultClientConfigImpl implements IClientConfig {
public static final long DEFAULT_POOL_KEEP_ALIVE_TIME = 15 * 60L;
public static final TimeUnit DEFAULT_POOL_KEEP_ALIVE_TIME_UNITS = TimeUnit.SECONDS;
}


public class OkHttpRibbonConfiguration {
@Value("${ribbon.client.name}")
private String name = "client";

@Configuration
protected static class OkHttpClientConfiguration {
private OkHttpClient httpClient;

@Bean
@ConditionalOnMissingBean(ConnectionPool.class)
public ConnectionPool httpClientConnectionPool(IClientConfig config, OkHttpClientConnectionPoolFactory connectionPoolFactory) {
Integer maxTotalConnections = config.getPropertyAsInteger(
CommonClientConfigKey.MaxTotalConnections,
DefaultClientConfigImpl.DEFAULT_MAX_TOTAL_CONNECTIONS);
Object timeToLiveObj = config
.getProperty(CommonClientConfigKey.PoolKeepAliveTime);
Long timeToLive = DefaultClientConfigImpl.DEFAULT_POOL_KEEP_ALIVE_TIME;
Object ttlUnitObj = config
.getProperty(CommonClientConfigKey.PoolKeepAliveTimeUnits);
TimeUnit ttlUnit = DefaultClientConfigImpl.DEFAULT_POOL_KEEP_ALIVE_TIME_UNITS;
if (timeToLiveObj instanceof Long) {
timeToLive = (Long) timeToLiveObj;
}
if (ttlUnitObj instanceof TimeUnit) {
ttlUnit = (TimeUnit) ttlUnitObj;
}
return connectionPoolFactory.create(maxTotalConnections, timeToLive, ttlUnit);
}

}






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Comments

Popular posts from this blog

paramiko-expect timeout is happening after executing the command

Export result set on Dbeaver to CSV

Opening a url is failing in Swift