NioServer: retain links by address string to minimize resource leak#3525
Conversation
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>
|
@blueorangutan package |
|
@rhtyd a Jenkins job has been kicked to build packages. I'll keep you posted as I make progress. |
|
Packaging result: ✔centos6 ✔centos7 ✔debian. JID-189 |
|
@blueorangutan test |
|
@rhtyd a Trillian-Jenkins test job (centos7 mgmt + kvm-centos7) has been kicked to run smoke tests |
|
Trillian test result (tid-230)
|
|
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. |
|
@rhtyd sounds intresting. LGTM. I think when anybody use a lb maybe the transparent mode can help? |
nathanejohnson
left a comment
There was a problem hiding this comment.
LGTM. I've built this locally in our lab and it seems to work well
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
left a comment
There was a problem hiding this comment.
code looks good and as to your caveat @rhtyd; can we add an identifier of sorts to the key of the hashmap?
|
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. |
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>
|
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. |
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
_linksweak hashmap to grow over time andvery 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:

When I restart the cloudstack-agent couple of times, I see the

_linksgrow:Types of changes