springcloud config坑系列一之Connection pool shut down on "zuul.host.*" property change
< 返回列表时间: 2019-10-28来源:OSCHINA
【围观】麒麟芯片遭打压成绝版,华为亿元投入又砸向了哪里?>>>
在使用springcloud config自动刷新功能难免会踩到一些坑,下面来介绍下 在生成中经常需要动态刷新配置,只需要增加@RefreshScope,并且执行手动刷新链接/actuator/refresh,或者集成springcloudbus来自动刷新,但是有些配置动态刷新时需要实例化一些spring内部复杂的对象,这里就不能自动更新了,比如说zuul。 zuul路由配置可以自动刷新, zuul: sensitive-headers: routes: api-b: path: /apib/** serviceId: dataeyeServer
但是设计到zuul内部resttemplate的一些超时配置,如果改动了,并且手动刷新,则会出现标题中的错误Connection pool shut down on "zuul.host.*" property change zuul: host: connect-timeout-millis: 10000 socket-timeout-millis: 600000
错误信息如下: java.lang.IllegalStateException: Connection pool shut down at org.apache.http.util.Asserts.check(Asserts.java:34) ~[httpcore-4.4.8.jar:4.4.8] at org.apache.http.pool.AbstractConnPool.lease(AbstractConnPool.java:191) ~[httpcore-4.4.8.jar:4.4.8] at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.requestConnection(PoolingHttpClientConnectionManager.java:257) ~[httpclient-4.5.3.jar:4.5.3] at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:176) ~[httpclient-4.5.3.jar:4.5.3] at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:185) ~[httpclient-4.5.3.jar:4.5.3] at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89) ~[httpclient-4.5.3.jar:4.5.3] at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:111) ~[httpclient-4.5.3.jar:4.5.3] at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185) ~[httpclient-4.5.3.jar:4.5.3] at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83) ~[httpclient-4.5.3.jar:4.5.3] at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56) ~[httpclient-4.5.3.jar:4.5.3] at org.springframework.http.client.HttpComponentsClientHttpRequest.executeInternal(HttpComponentsClientHttpRequest.java:89) ~[spring-web-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48) ~[spring-web-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:53) ~[spring-web-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:659) ~[spring-web-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:628) ~[spring-web-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.web.client.RestTemplate.getForObject(RestTemplate.java:302) ~[spring-web-4.3.13.RELEASE.jar:4.3.13.RELEASE]
这是由于自动刷新时,由于host中超时时间配置变更导致连接池先关闭,再准备重新创建,但是在重现创建的过程中却没有重新创建连接池,还是引用原有连接池导致报错。 解决方案一:将springcloud升级到Edgware.RELEASE,即 spring-cloud-commons-dependencies 版本升级到1.3.2.RELEASE
解决方案二:手动实例化连接池
参考资料 https://github.com/spring-cloud/spring-cloud-netflix/issues/3406
https://github.com/spring-cloud/spring-cloud-commons/issues/330
https://github.com/spring-cloud/spring-cloud-config/issues/918
热门排行