flow icon indicating copy to clipboard operation
flow copied to clipboard

Jsoup ThreadLocal memory leak (again)

Open scrmtrey91 opened this issue 2 years ago • 9 comments

Describe the bug

The web application [/App] created a ThreadLocal with key of type [org.jsoup.internal.StringUtil$1] (value [org.jsoup.internal.StringUtil$1@361160a7]) and a value of type [java.util.Stack] (value [[]]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.]]

Not directly Vaadin related. More JSOUP issue but still.

This is with jsoup from vaadin bom and also from latest jsoup version on maven. This was exact same problem in some version of jsoup in vaadin 8 which has been fixed by using different jsoup version. My workstation starting to freeze because there was no memory left (31.9 used / 32gb).

image_2021_11_11T12_29_12_905Z

Expected-behavior

No memory leak / no message like this.

I have another app with vaadin 19 and there is no such issue (because of different jsoup version).

Reproduction

It is just a normal vaadin application.

System Info

Windows 11 Vaadin 14.7.4 - Vaadin 14.7.5 (without spring boot) Java 8

scrmtrey91 avatar Nov 12 '21 18:11 scrmtrey91

Thanks for using Vaadin Platform, we appreciate your help and are going to take care of this as soon as possible.

vaadin-bot avatar Nov 12 '21 18:11 vaadin-bot

Looks like jsoup dependency is from flow actually. Ahh...

JSOUP version 1.12.1 looks fine.

Maybe this commit : JSOUP update commit

scrmtrey91 avatar Nov 12 '21 18:11 scrmtrey91

You should probably create this issue on the jsoup repo as well, if you can create a simple reproduce-able case. Vaadin / Flow had to update because of security issues in the older versions.

knoobie avatar Nov 12 '21 20:11 knoobie

Hello. Could you provide a bit more details on what to do to reproduce this issue ?

It is just a normal vaadin application.

Is just not enough and we don't recall seeing any reports about this elsewhere. When I looked at the JSoup code, it seems quite clear what it is trying to do - but I don't see how / where the leakage could happen as the stack stores only some of the used StringBuilder instances to be reused later on.

pleku avatar Nov 22 '21 08:11 pleku

Here you go. Sample project from GITHUB.

  • Vaadin 14.7.5 with vaadin-cdi.
  • Java 11.
  • Deployed on payara 5.2021.3 server.

server.log (afte couple of F5 and button clicks):

[2021-11-22T19:10:15.441+0100] [Payara 5.2021.8] [SEVERE] [] [javax.enterprise.web.util] [tid: _ThreadID=115 _ThreadName=admin-thread-pool::admin-listener(1)] [timeMillis: 1637604615441] [levelValue: 1000] [[ The web application [/project-base-flow-cdi-1.0-SNAPSHOT] created a ThreadLocal with key of type [org.jsoup.internal.StringUtil$1] (value [org.jsoup.internal.StringUtil$1@afac71a]) and a value of type [java.util.Stack] (value [[]]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.]]

[2021-11-22T19:10:15.441+0100] [Payara 5.2021.8] [SEVERE] [] [javax.enterprise.web.util] [tid: _ThreadID=115 _ThreadName=admin-thread-pool::admin-listener(1)] [timeMillis: 1637604615441] [levelValue: 1000] [[ The web application [/project-base-flow-cdi-1.0-SNAPSHOT] created a ThreadLocal with key of type [org.jsoup.internal.StringUtil$1] (value [org.jsoup.internal.StringUtil$1@afac71a]) and a value of type [java.util.Stack] (value [[]]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.]]

[2021-11-22T19:10:15.441+0100] [Payara 5.2021.8] [SEVERE] [] [javax.enterprise.web.util] [tid: _ThreadID=115 _ThreadName=admin-thread-pool::admin-listener(1)] [timeMillis: 1637604615441] [levelValue: 1000] [[ The web application [/project-base-flow-cdi-1.0-SNAPSHOT] created a ThreadLocal with key of type [org.jsoup.internal.StringUtil$1] (value [org.jsoup.internal.StringUtil$1@afac71a]) and a value of type [java.util.Stack] (value [[]]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.]]

[2021-11-22T19:10:15.441+0100] [Payara 5.2021.8] [SEVERE] [] [javax.enterprise.web.util] [tid: _ThreadID=115 _ThreadName=admin-thread-pool::admin-listener(1)] [timeMillis: 1637604615441] [levelValue: 1000] [[ The web application [/project-base-flow-cdi-1.0-SNAPSHOT] created a ThreadLocal with key of type [org.jsoup.internal.StringUtil$1] (value [org.jsoup.internal.StringUtil$1@afac71a]) and a value of type [java.util.Stack] (value [[]]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.]]

[2021-11-22T19:10:15.441+0100] [Payara 5.2021.8] [SEVERE] [] [javax.enterprise.web.util] [tid: _ThreadID=115 _ThreadName=admin-thread-pool::admin-listener(1)] [timeMillis: 1637604615441] [levelValue: 1000] [[ The web application [/project-base-flow-cdi-1.0-SNAPSHOT] created a ThreadLocal with key of type [org.jsoup.internal.StringUtil$1] (value [org.jsoup.internal.StringUtil$1@afac71a]) and a value of type [java.util.Stack] (value [[]]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.]]

[2021-11-22T19:10:16.895+0100] [Payara 5.2021.8] [INFO] [] [org.apache.deltaspike.core.util.ProjectStageProducer] [tid: _ThreadID=115 _ThreadName=admin-thread-pool::admin-listener(1)] [timeMillis: 1637604616895] [levelValue: 800] [[ Computed the following DeltaSpike ProjectStage: Production]]

Sample project, just basic vaadin with cdi (maven project). skeleton-starter-flow-cdi-master.zip

scrmtrey91 avatar Nov 22 '21 18:11 scrmtrey91

I at least couldn't replicate the issue where memory would be used up with any noticable rate with the given project. Only difference in environments would be that I'm still on window 10 instead of 11

caalador avatar Nov 30 '21 07:11 caalador

Probably depends on how large is project. Also it depends on how many objects are injected via cdi (uiscoped etc) and also how much data entities are loaded into UI (grid, comboboxes etc).

Each deploy take some of RAM, especialy when developing the app (alot of deploy - test - fix - depoy - test ,....).

scrmtrey91 avatar Nov 30 '21 08:11 scrmtrey91

Could you try with a newer versions of Vaadin? The latest one is 14.8.14 https://github.com/vaadin/platform/releases/tag/14.8.14 .

mshabarov avatar Jul 28 '22 14:07 mshabarov

We've recently updated all maintained Flow versions with Jsoup 1.15.3. As we couldn't reproduce the issue, we assume that the issue is fixed in the later version of Jsoup. Please reopen this issue or create a new one if you still the same problem.

mshabarov avatar Sep 13 '22 08:09 mshabarov