Skip to content

fix httpclient5.x connection leak #3727

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
May 15, 2025

Conversation

JoeCqupt
Copy link
Contributor

@JoeCqupt JoeCqupt commented Mar 17, 2025

@spencergibb
Copy link
Member

So this change breaks the build in the retry tests.

Error:    RetryFilterFunctionTests.retryBodyWorks:91 Status expected:<200 OK> but was:<500 INTERNAL_SERVER_ERROR>
Error:    RetryFilterFunctionTests.retryWorks:72 Status expected:<200 OK> but was:<500 INTERNAL_SERVER_ERROR>

@spencergibb
Copy link
Member

Hmm, locally they pass. Rerunning build.

@spencergibb
Copy link
Member

Any idea how to test this? The test in the reproducer in #3696 doesn't pass with this fix.

@JoeCqupt JoeCqupt force-pushed the fix-connection-leak branch from 5428e24 to eb28861 Compare March 18, 2025 04:57
@JoeCqupt JoeCqupt force-pushed the fix-connection-leak branch 4 times, most recently from 86e28b0 to aeffc5e Compare March 31, 2025 05:51
@JoeCqupt
Copy link
Contributor Author

Any idea how to test this? The test in the reproducer in #3696 doesn't pass with this fix.

the reproducer code with some error config . the route uri not match mock server .

@JoeCqupt
Copy link
Contributor Author

@spencergibb @ryanjbaxter PTAL

@ryanjbaxter
Copy link
Contributor

Could we use the reproducer as a basis for a test?

@JoeCqupt
Copy link
Contributor Author

JoeCqupt commented Apr 3, 2025

Could we use the reproducer as a basis for a test?

i have use the reproducer code as a basis add a unit test .

Let me explain the code which i modified:

first i add httpclient5 maven dependency for test

<dependency>
    <groupId>org.apache.httpcomponents.client5</groupId>
    <artifactId>httpclient5</artifactId>
    <scope>test</scope>
</dependency>

but this changed the underlying implementation of ProxyExchange : change from REACTOR to HTTP_COMPONENTS . refer to ClientHttpRequestFactoryBuilder

so i add config to application.yml

spring:
  http:
    client:
      factory: REACTOR

After modifying the config , I modified two associated unit tests:
GatewayServerMvcAutoConfigurationTests#gatewayHttpClientPropertiesWork
GatewayServerMvcAutoConfigurationTests#settingHttpClientFactoryWorks

Finally i add a unit test to test httpcommonts as the underlying implementation of ProxyExchange

@ryanjbaxter @spencergibb PTAL

@ryanjbaxter
Copy link
Contributor

Can you elaborate on why you needed to add httpclient5?

@JoeCqupt
Copy link
Contributor Author

Can you elaborate on why you needed to add httpclient5?

because the reproducer code use httpclient5 as the underlying implementation of ProxyExchange

issue : #3696
reproducer code: https://github.com/johan1a/spring-cloud-gateway-mvc-connection-test/blob/master/src/main/java/com/example/demo/HttpComponentsConfig.java#L14-L20

Copy link
Member

@spencergibb spencergibb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JoeCqupt unfortunately, adding the Apache httpclient 5 dependency will change the underlying http client for all the tests. You would need to add a new integration test module to not pollute the classpath here https://github.com/spring-cloud/spring-cloud-gateway/tree/main/spring-cloud-gateway-integration-tests

@JoeCqupt
Copy link
Contributor Author

@JoeCqupt unfortunately, adding the Apache httpclient 5 dependency will change the underlying http client for all the tests. You would need to add a new integration test module to not pollute the classpath here https://github.com/spring-cloud/spring-cloud-gateway/tree/main/spring-cloud-gateway-integration-tests

OK i will add a new integration test

@JoeCqupt JoeCqupt requested a review from spencergibb April 21, 2025 03:42
@ryanjbaxter
Copy link
Contributor

Can you submit this against the 4.1.x branch?

@JoeCqupt JoeCqupt changed the base branch from main to 4.1.x May 15, 2025 06:10
@JoeCqupt JoeCqupt changed the base branch from 4.1.x to main May 15, 2025 07:13
@JoeCqupt JoeCqupt force-pushed the fix-connection-leak branch from 44a9c81 to f61173c Compare May 15, 2025 08:45
@JoeCqupt JoeCqupt changed the base branch from main to 4.1.x May 15, 2025 08:45
@JoeCqupt JoeCqupt force-pushed the fix-connection-leak branch from f61173c to 5f87ba4 Compare May 15, 2025 08:51
@JoeCqupt JoeCqupt changed the base branch from 4.1.x to main May 15, 2025 09:19
@JoeCqupt JoeCqupt changed the base branch from main to 4.1.x May 15, 2025 09:20
JoeCqupt added 7 commits May 15, 2025 17:27
Signed-off-by: joecqupt <[email protected]>
Signed-off-by: jiangyuan <[email protected]>
Signed-off-by: jiangyuan <[email protected]>

test ci build
Signed-off-by: jiangyuan <[email protected]>
Signed-off-by: jiangyuan <[email protected]>
@JoeCqupt JoeCqupt force-pushed the fix-connection-leak branch from 5f87ba4 to 4ff93c5 Compare May 15, 2025 09:28
@JoeCqupt
Copy link
Contributor Author

JoeCqupt commented May 15, 2025

Can you submit this against the 4.1.x branch?

i have changed the base branch to 4.1.x

@ryanjbaxter ryanjbaxter merged commit cd21135 into spring-cloud:4.1.x May 15, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants