[BUG] 多个实例部署,偶尔个别实例文件句柄不能释放,导致上游调用请求网关超时返回504异常
- Dominant language
- Java
- Stars
- 8.8k
- Forks
- 3.1k
- Avg merge
- 7d 1h
- Merged PRs (30d)
- 85
Description
### Is there an existing issue for this?
- [x] I have searched the existing issues
### Current Behavior
shenyu代码版本:2.5.1
HttpClient配置:
shenyu.httpclient.keepAlive = true
shenyu.httpclient.pool.type = FIXED
shenyu.httpclient.pool.name = proxy
shenyu.httpclient.pool.acquireTimeout = 3000
shenyu.httpclient.pool.maxIdleTime = 10000
shenyu.httpclient.connectTimeout = 5000
shenyu.httpclient.maxInMemorySize = 10
bean定义
```java
@Bean
public HttpClient httpClient(final HttpClientProperties properties,
final ObjectProvider provider) {
// configure pool resources.
HttpClientProperties.Pool pool = properties.getPool();
ConnectionProvider connectionProvider = buildConnectionProvider(pool);
HttpClient httpClient = HttpClient.create(connectionProvider)
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, properties.getConnectTimeout());
HttpClientProperties.Proxy proxy = properties.getProxy();
if (StringUtils.isNotEmpty(proxy.getHost())) {
httpClient = setHttpClientProxy(httpClient, proxy);
}
httpClient.doOnConnected(connection -> {
connection.addHandlerLast(new IdleStateHandler(properties.getReaderIdleTime(), properties.getWriterIdleTime(), properties.getAllIdleTime(), TimeUnit.MILLISECONDS));
connection.addHandlerLast(new WriteTimeoutHandler(properties.getWriteTimeout(), TimeUnit.MILLISECONDS));
connection.addHandlerLast(new ReadTimeoutHandler(properties.getReadTimeout(), TimeUnit.MILLISECONDS));
});
final LoopResources loopResources = provider.getIfAvailable();
if (Objects.nonNull(loopResources)) {
httpClient.runOn(loopResources);
}
HttpClientProperties.Ssl ssl = properties.getSsl();
if (StringUtils.isNotEmpty(ssl.getKeyStorePath())
|| ArrayUtils.isNotEmpty(ssl.getTrustedX509CertificatesForTrustManager())
|| ssl.isUseInsecureTrustManager()) {
httpClient = httpClient.secure(sslContextSpec -> setSsl(sslContextSpec, ssl));
}
if (properties.isWiretap()) {
httpClient = httpClient.wiretap(true);
}
// set to false, fix java.io.IOException: Connection reset by peer
// see https://github.com/reactor/reactor-netty/issues/388
return httpClient.keepAlive(properties.isKeepAlive());
}
//使用默认的webclient客户端请求业务系统,
@Configuration
@ConditionalOnProperty(name = "shenyu.httpclient.strategy", havingValue = "webClient", matchIfMissing = true)
static class WebClientConfiguration {
/**
* Web client plugin shenyu plugin.
*
* @param httpClient the http client
* @return the shenyu plugin
*/
@Bean
public ShenyuPlugin webClientPlugin(
final HttpClientProperties properties,
final ObjectProvider httpClient) {
WebClient webClient = WebClient.builder()
// fix Exceeded limit on max bytes to buffer
// detail see https://stackoverflow.com/questions/59326351/configure-spring-codec-max-in-memory-size-when-using-reactiveelasticsearchclient
.exchangeStrategies(ExchangeStrategies.builder()
.codecs(codecs -> codecs.defaultCodecs().maxInMemorySize(properties.getMaxInMemorySize() * 1024 * 1024))
.build())
.clientConnector(new ReactorClientHttpConnector(Objects.requireNonNull(httpClient.getIfAvailable())))
.build();
return new WebClientPlugin(webClient);
}
}
```
### Expected Behavior
_No response_
### Steps To Reproduce
_No response_
### Environment
```markdown
ShenYu version(s):2.5.1
```
### Debug logs
日志中没有报错信息
### Anything else?
_No response_
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the HttpClient bean definition and the WebClientConfiguration shown in the report, then inspect the configured connection pool, keep-alive behavior, and timeout handlers. Reproduce the issue with multiple ShenYu 2.5.1 instances using the supplied settings and review the gateway logs during upstream 504 responses. Done means the affected instances release file handles reliably and upstream requests no longer time out under the reported deployment pattern.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100