Skip to content

NioServer: retain links by address string to minimize resource leak#3525

Merged
yadvr merged 1 commit into
apache:masterfrom
shapeblue:nioserver-memory-leak-fix
Oct 22, 2019
Merged

NioServer: retain links by address string to minimize resource leak#3525
yadvr merged 1 commit into
apache:masterfrom
shapeblue:nioserver-memory-leak-fix

Conversation

@yadvr

@yadvr yadvr commented Jul 26, 2019

Copy link
Copy Markdown
Member

Every time a client connects, the NioServer will retain the link against
the InetSocketAddress object. If the same agent/client reconnects, it
will grow older links over time and in case of denial of service attack
or a client/script/monitoring-service reconnecting aggressively against
port 8250 will cause the _links weak hashmap to grow over time and
very quickly.

The fix will ensure that only one Link gets weakly retained for an
incoming client based on its address string.

This is what is seen when only one kvm/agent connects to the management server:
Screenshot from 2019-07-26 16-24-05

When I restart the cloudstack-agent couple of times, I see the _links grow:
Screenshot from 2019-07-26 16-24-17

Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)
  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (improves an existing feature and functionality)
  • Cleanup (Code refactoring and cleanup, that may add test cases)

Every time a client connects, the NioServer will retain the link against
the InetSocketAddress object. If the same agent/client reconnects, it
will grow older links over time and in case of denial of service attack
or a client/script/monitoring-service reconnecting aggressively against
port 8250 will cause the `_links` weak hashmap to grow over time and
very quickly.

The fix will ensure that only one Link gets weakly retained for an
incoming client based on its address string.

Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
@yadvr yadvr added this to the 4.13.0.0 milestone Jul 26, 2019
@yadvr

yadvr commented Jul 26, 2019

Copy link
Copy Markdown
Member Author

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@rhtyd a Jenkins job has been kicked to build packages. I'll keep you posted as I make progress.

@blueorangutan

Copy link
Copy Markdown

Packaging result: ✔centos6 ✔centos7 ✔debian. JID-189

@yadvr

yadvr commented Jul 26, 2019

Copy link
Copy Markdown
Member Author

@blueorangutan test

@blueorangutan

Copy link
Copy Markdown

@rhtyd a Trillian-Jenkins test job (centos7 mgmt + kvm-centos7) has been kicked to run smoke tests

@blueorangutan

Copy link
Copy Markdown

Trillian test result (tid-230)
Environment: kvm-centos7 (x2), Advanced Networking with Mgmt server 7
Total time taken: 26166 seconds
Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr3525-t230-kvm-centos7.zip
Smoke tests completed. 77 look OK, 0 have error(s)
Only failed tests results shown below:

Test Result Time (s) Test File

@yadvr yadvr modified the milestones: 4.13.0.0, 4.13.1.0 Jul 27, 2019
@yadvr

yadvr commented Jul 29, 2019

Copy link
Copy Markdown
Member Author

Caveat: for multiple-mgmt servers behind an LB, it will end up creating only one weak entry in the weak hash map. I'm not sure if it could cause any issues.

@svenvogel

Copy link
Copy Markdown
Contributor

@rhtyd sounds intresting. LGTM. I think when anybody use a lb maybe the transparent mode can help?

@nathanejohnson nathanejohnson left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. I've built this locally in our lab and it seems to work well

@DaanHoogland

Copy link
Copy Markdown
Contributor

Caveat: for multiple-mgmt servers behind an LB, it will end up creating only one weak entry in the weak hash map. I'm not sure if it could cause any issues.

Do you mean that the two servers would share that hashmap, @rhtyd ? that seem strange to me. And if you mean on the agent side, that would only be a problem if the MSses are natted behind the same address, would it?

@DaanHoogland DaanHoogland left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

code looks good and as to your caveat @rhtyd; can we add an identifier of sorts to the key of the hashmap?

@yadvr

yadvr commented Aug 13, 2019

Copy link
Copy Markdown
Member Author

In case of mgmt servers behind an LB, this will likely create a single entry in the weak hashmap. I'll revisit this towards 4.14 or 4.13.1; it's also possible to add a garbage collector to remove old/unreachable links from the heap.

@yadvr yadvr removed this from the 4.13.1.0 milestone Oct 22, 2019
@yadvr yadvr added this to the 4.14.0.0 milestone Oct 22, 2019
@yadvr
yadvr merged commit 9ee129a into apache:master Oct 22, 2019
yadvr added a commit that referenced this pull request Oct 22, 2019
This reverts "9ee129ae6a08935645734ad520bec72bf5f22217" from #3525, as
the solution is not optimal and would cause a single Link to be added
in the Map if management server is behind a LB.

Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
@yadvr

yadvr commented Oct 22, 2019

Copy link
Copy Markdown
Member Author

Sorry, reverting this PR because I remembered why it was put On-Hold, as the change would cause a single Link to be added to a Map when the mgmt server is behind a LB. So the changes are not optimal for all cases.

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.

5 participants