wso2 / product-is

Welcome to the WSO2 Identity Server source code! For info on working with the WSO2 Identity Server repository and contributing code, click the link below.
http://wso2.github.io/
Apache License 2.0
727 stars 713 forks source link

Dynalink leaks memory when adaptive authentication scripts are used with JDK 11 #16597

Open deshankoswatte opened 10 months ago

deshankoswatte commented 10 months ago

Describe the issue:

When adaptive authentication scripts are used with JDK 11 a memory leak identified at JDK's end [1] causes the WSO2 Identity Server (WSO2 IS) to go out of memory (OOM). The heap memory rises and it does not get cleared up.

How to reproduce:

In my case, the -Xmx was configured to the default value of 1024, and the authorize calls sent during that time added up to about 1 million requests.

Sample screenshots with the evidence are attached below:

Heap Dump Analysis:

dynalink-leak

JConsole Overview during the test:

jconsole-stat

Expected behavior:

The fix for the issue is provided with JDK 17 but it has not been sent out to JDK 11. If the fix is not ported to JDK 11 alternatives should be looked into.

Environment information (Please complete the following information; remove any unnecessary fields) :

References:

[1] - https://bugs.openjdk.org/browse/JDK-8198540


deshankoswatte commented 9 months ago

The aforementioned issue was tested with WSO2 IS 6.0.0.119 using JDK 17.0.7, and it appears that the issue has been resolved. The same test mentioned above was conducted for approximately 3 hours, and the JConsole results were as follows. As you can observe, the heap now clears properly when compared to the screenshot included in the previous comment.

Screenshot from 2023-09-18 11-37-44

Furthermore, we acquired a heap dump and analyzed it to verify the presence of Dynalink objects. However, we could not locate any such objects in the two heap dumps that were obtained. The screenshot below provides further illustration.

Screenshot from 2023-09-18 11-51-05

hwupathum commented 9 months ago

The above issue was tested with WSO2 IS 5.10.0.248 with Java 11.0.20. I used a JMeter script to call the authorize endpoint indefinitely and was able to observe the same increase of memory. I observed that the Old Gen memory is increasing linearly with the number of executions and becomes static when the test script is stopped.

Old Generation Heap:

Screenshot 2023-09-25 at 13 24 38

Total Heap:

Screenshot 2023-09-25 at 13 24 44

Tested the same script in Java 8 and noticed that the Old Generation memory is reduced frequantly than with Java 11.

Old Generation Heap:

Screenshot 2023-09-25 at 10 28 29

Total Heap:

Screenshot 2023-09-25 at 10 28 40
shanggeeth commented 7 months ago

Temporary fix: https://github.com/wso2/carbon-identity-framework/pull/5202