springcloud config坑系列一之Connection pool shut down on "zuul.host.*" property change

在使用springcloud config自動刷新功能不免會踩到一些坑,下面來介紹下 在生成中常常須要動態刷新配置,只須要增長@RefreshScope,而且執行手動刷新連接/actuator/refresh,或者集成springcloudbus來自動刷新,可是有些配置動態刷新時須要實例化一些spring內部複雜的對象,這裏就不能自動更新了,好比說zuul。 zuul路由配置能夠自動刷新,java

zuul:
  sensitive-headers:
  routes:
    api-b:
      path: /apib/**
      serviceId: dataeyeServer

可是設計到zuul內部resttemplate的一些超時配置,若是改動了,而且手動刷新,則會出現標題中的錯誤Connection pool shut down on "zuul.host.*" property changegit

zuul:
  host:
    connect-timeout-millis: 10000
    socket-timeout-millis: 600000

錯誤信息以下:github

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.RELEASEweb

解決方案二:手動實例化鏈接池spring

 

參考資料 https://github.com/spring-cloud/spring-cloud-netflix/issues/3406apache

https://github.com/spring-cloud/spring-cloud-commons/issues/330api

https://github.com/spring-cloud/spring-cloud-config/issues/918socket

相關文章
相關標籤/搜索