Skip to content
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

Fix memory leak of HTTP server on bind failure #2844

Merged
merged 6 commits into from
Jun 29, 2023

Conversation

SgtSilvio
Copy link
Contributor

Fix issue #2843 by closing channel on bind (and other) exception

@pivotal-cla
Copy link

@SgtSilvio Please sign the Contributor License Agreement!

Click here to manually synchronize the status of this Pull Request.

See the FAQ for frequently asked questions.

@pivotal-cla
Copy link

@SgtSilvio Thank you for signing the Contributor License Agreement!

Copy link
Member

@violetagg violetagg left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

Can you provide a test?

@violetagg violetagg added the type/bug A general bug label Jun 28, 2023
@violetagg violetagg added this to the 1.0.34 milestone Jun 28, 2023
@violetagg violetagg linked an issue Jun 28, 2023 that may be closed by this pull request
@SgtSilvio
Copy link
Contributor Author

Can you provide a test?

Good point.
The original issue with the memory leak on bind failure is pretty hard to test, as the TransportConnector.bind method does not return a handle of the channel in that case. Maybe we can get a handle by overriding TransportConfig.connectionFactory in the test.

@violetagg
Copy link
Member

May be we can limit the test to checking channel is opened or not?

@violetagg
Copy link
Member

violetagg commented Jun 28, 2023

May be something like this below:

List<Channel> channels = new ArrayList<>();
HttpServer.create().doOnChannelInit((obs, ch, addr) -> channels.add(ch))....;
// Inspect channel.isOpen()

@violetagg
Copy link
Member

May be something like this below:

List<Channel> channels = new ArrayList<>();
HttpServer.create().doOnChannelInit((obs, ch, addr) -> channels.add(ch))....;
// Inspect channel.isOpen()

Do you think this will help for the test?

@SgtSilvio
Copy link
Contributor Author

I will still provide a test, but doOnChannelInit does not work unfortunately as this is only called for child channels and not for the server channel.

@violetagg
Copy link
Member

I will still provide a test, but doOnChannelInit does not work unfortunately as this is only called for child channels and not for the server channel.

ouch correct ...

Then try directly to test TransportConnector.bind and just mock the TransportConfig.

Something like

SocketAddress socketAddress = new InetSocketAddress("localhost", 12345);
List<Channel> channels = new ArrayList<>();
ChannelInitializer<Channel> channelInitializer = new ChannelInitializer<Channel>() {
	@Override
	protected void initChannel(Channel ch) {
		channels.add(ch);
	}
};
TransportConnector.bind(mockConfig, channelInitializer, socketAddress, false)

@SgtSilvio
Copy link
Contributor Author

Thanks, now added a test that fails without and succeeds with the changes.

@violetagg
Copy link
Member

Can you update also TransportConnector copyright end year?

> The following files had format violations:
      reactor-netty-core/src/main/java/reactor/netty/transport/TransportConnector.java
          @@ -1,5 +1,5 @@
           /*
          -·*·Copyright·(c)·2020-2022·VMware,·Inc.·or·its·affiliates,·All·Rights·Reserved.
          +·*·Copyright·(c)·2020-2023·VMware,·Inc.·or·its·affiliates,·All·Rights·Reserved.
           ·*
           ·*·Licensed·under·the·Apache·License,·Version·2.0·(the·"License");
           ·*·you·may·not·use·this·file·except·in·compliance·with·the·License.
  Run './gradlew :spotlessApply' to fix these violations.

Copy link
Member

@violetagg violetagg left a comment

Choose a reason for hiding this comment

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

@reactor/netty-team PTAL

Copy link
Contributor

@pderop pderop left a comment

Choose a reason for hiding this comment

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

@SgtSilvio , nice !

+1

@violetagg violetagg changed the title Fix "Memory leak of HTTP server on bind failure" Fix memory leak of HTTP server on bind failure Jun 29, 2023
@violetagg violetagg merged commit 625633e into reactor:main Jun 29, 2023
@SgtSilvio
Copy link
Contributor Author

Thanks for the very quick handling!

@SgtSilvio SgtSilvio deleted the bugfix/2843-bind-memory-leak branch June 29, 2023 08:14
violetagg pushed a commit that referenced this pull request Jun 29, 2023
Fixes #2843 by closing channel on bind (and other) exception
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug A general bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Memory leak of HTTP server on bind failure
4 participants