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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

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
Signed-off-by: joecqupt <[email protected]>
Signed-off-by: jiangyuan <[email protected]>
@JoeCqupt JoeCqupt force-pushed the fix-connection-leak branch from eb28861 to 6ce0e1d Compare March 26, 2025 03:53
@JoeCqupt JoeCqupt force-pushed the fix-connection-leak branch 2 times, most recently from f0dfe66 to 86e28b0 Compare March 31, 2025 05:47
Signed-off-by: jiangyuan <[email protected]>

test ci build
@JoeCqupt JoeCqupt force-pushed the fix-connection-leak branch 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 added 2 commits April 3, 2025 01:05
Signed-off-by: jiangyuan <[email protected]>
Signed-off-by: jiangyuan <[email protected]>
@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

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