-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
RestTemplateEurekaHttpClient not closing HttpClient on shutdown #4103
Comments
spring-projects/spring-boot#31075 (comment)
|
Hello, @BenEfrati , thanks for reporting it. Looks like a bug. |
Recently, I encountered this problem in the production environment. I found that the
|
Hello @sdzx3783 - thanks for your comment. Would you like to submit a PR with a fix? |
I provide a temporary solution without changing the source code |
Hi @OlgaMaciaszek , may I know which version will include the fix? |
@dangkhoaphung if the issue is added to an active backlog, it will be assigned a milestone. We're now prioritising tasks for the upcoming release and will circle back to non-blocking issues later on. However, feel free to create a PR, and we will definitely review it. |
Initial fix reverted due to #4275. Reopening. |
Spring Cloud eureka client 4.1.3 hi, I upgraded to 4.1.3 and still have a lot of close_wait problems. |
Is there any plan to fix this issue in which version? |
Yes, @impactCn. the initial fix had to be reverted due to regression. We'll need to work on another fix, however it's not yet assigned to a new backlog. We some higher priority task right now, but I will try to look into it next month. |
@OlgaMaciaszek I have a temporary solution to solve this problem, using webflux's webclient as the caller. I don't seem to have this problem in the test environment. I'll test it in the production environment tomorrow and take a look. |
Sounds good @impactCn. Please take a look at that regression linked above as well to see if your solution is not doing the same. If it works fine, please feel free to create a PR or share the workaround. |
@OlgaMaciaszek |
Ah, ok - that's a different thing - it's just using WebClient instead of |
Spring Cloud 2021.0.0
Spring Boot 2.6.8
Bug Description:
RestTemplateEurekaHttpClient
is not closingHttpClient
on shutdown. This leads to TCPCLOSE_WAIT
connections to eureka server.EurekaClient
will shutdown when an exception occurs on an http request, but not shutdownHttpClient
.This bug is related to
spring-cloud-netflix/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/http/RestTemplateEurekaHttpClient.java
Line 203 in 27ac337
In case of exception here:
https://github.com/Netflix/eureka/blob/ed0da19ca1c049c87e3dbf75b6015c1861d5c2d0/eureka-client/src/main/java/com/netflix/discovery/shared/transport/decorator/RedirectingEurekaHttpClient.java#L96
new
HttpClient
will be created without closing the existing one - this causesCLOSE_WAIT
connectionsThis supplier creates new
CloseableHttpClient
for every call tospring-cloud-netflix/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/http/RestTemplateTransportClientFactory.java
Line 103 in 27ac337
so in case of shutdown,
currentEurekaClient
shutdown don't closes connections:spring-cloud-netflix/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/http/RestTemplateEurekaHttpClient.java
Line 203 in 27ac337
possible solution will be trying to close the
HttpClient
:shutdown
could beunwrapRequestFactoryIfNecessary
https://github.com/spring-projects/spring-boot/blob/47516b50c39bd6ea924a1f6720ce6d4a71088651/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/client/RestTemplateBuilder.java#L746
spring-projects/spring-boot#31075
As you can see process open files increases over time until GC occurred

We can also create
EurekaClientHttpRequestFactorySupplier
which return the sameClientHttpRequestFactory
, but it not a stable solution since we can't control eureka client code, maybe in case of exceptions connections not closes (hence not returns toPoolingHttpClientConnectionManager
) - this can lead to no available connections in pool. In that case, restart is requiredOriginal Issue:
#4062
The text was updated successfully, but these errors were encountered: