You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Christopher Schultz <ch...@christopherschultz.net> on 2014/09/17 21:55:48 UTC

DBCP2 holding references to WebappClassLoader; resource leak

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

All,

I'm running Tomcat 8.0.9 on Mac OS X under Oracle's Java 7 jdk1.7.0_65.

For a long time, I've had a cleanly reloading web application, meaning
that after my web application is reloaded (say, during development),
the old WebappClassLoader is available for GC.

After switching to Tomcat 8.x in my development environment, I've
noticed that I can't cleanly reload anymore. Using YourKit, I've
traced the reference to my WebappClassLoader to DBCP2.

I have a JNDI DataSource whose JDBC driver is loaded from Tomcat's
CATALINA_HOME/lib directory.

It seems that org.apache.tomcat.dbcp.pool2.impl.GenericObjectPool has
a member, factoryClassLoader, which points to my WebappClassLoader. I
believe that it will likely retain that reference after multiple
reloads, so I'm only leaking a single WebappClassLoader.

I think we probably want to use the ClassLoader of the JDBC driver for
the DBCP pool as well. Can anyone confirm that this happens to them as
well?

Thanks,
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
Comment: GPGTools - http://gpgtools.org

iQIbBAEBCAAGBQJUGedCAAoJEBzwKT+lPKRYxxcP+NJRqWAxy+J7oV8jnkVPemgR
v38zegtoUnwBcqeb7cjnnE8QPHpvl8nTXFRmH5FqB/EhCSYMsyF53sqm/UyMOcr1
d7/LKILpclBgAg+XoOEyCgl+Eeu2A1vSD7ThiyqUNK5IxddkJHtI+04LTYL4Ym3w
LWCSS2fElTkcz07BgBY9XHak2nYlUVPEpmRAQynjOIHo2Z+PLpLh4iWePsdLdzYw
c7ZmMX2CfxRL4OuBzrL/T6sCpcX/4pi2nEnloeqe2/KG9dYEeOb58l9LvBThoj6t
lfNAeV+gGwuV5GjzD3m+7LLhae40EDzfgBn60jzGy5edcKTCoXjdMDODtipsohY0
jmktvG9UHPegXlYWAHwVPgyk2GwqKiVKvnMFesJuI9xvGDe/MwZ5tiM+356mBMot
xb88w+OcmOYEVyjxHWf9AOPpcNDTDbZmxN0U2JbqgLEu2GgWNtemnptte0+WbfAR
i/XMSxYSiuVgP1SXJkOqWlFwyDvdM5tMhrwI+FYriI7WiIOw/rxA0A9hAHRHmBs2
kYySM5ANB1JmZqWMKuRENQ7J1TLKAoMS9PdE6GNJaGI/xDv5qNpQn+/3b5mJlX+a
7jrW2Vlnd+poFoTfTn6SUOX+H21h4fk4bx2kRFcP3EYHx3qN3SMKmw4bHoWMLN8+
lidtkY2O+GPue4O9uQ8=
=UMbo
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: DBCP2 holding references to WebappClassLoader; resource leak

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Mark,

On 9/23/14 10:18 AM, Christopher Schultz wrote:
> Mark,
> 
> On 9/23/14 5:52 AM, Mark Thomas wrote:
>> On 22/09/2014 13:50, Christopher Schultz wrote:
>>> Mark,
>>> 
>>> On 9/17/14 4:06 PM, Christopher Schultz wrote:
>>>> Mark,
>>> 
>>>> On 9/17/14 4:02 PM, Mark Thomas wrote:
>>>>> On 17/09/2014 20:55, Christopher Schultz wrote:
>>>>>> All,
>>>>>> 
>>>>>> I'm running Tomcat 8.0.9 on Mac OS X under Oracle's Java
>>>>>> 7 jdk1.7.0_65.
>>>>>> 
>>>>>> For a long time, I've had a cleanly reloading web 
>>>>>> application, meaning that after my web application is 
>>>>>> reloaded (say, during development), the old 
>>>>>> WebappClassLoader is available for GC.
>>>>>> 
>>>>>> After switching to Tomcat 8.x in my development 
>>>>>> environment, I've noticed that I can't cleanly reload 
>>>>>> anymore. Using YourKit, I've traced the reference to my 
>>>>>> WebappClassLoader to DBCP2.
>>>>>> 
>>>>>> I have a JNDI DataSource whose JDBC driver is loaded from
>>>>>>  Tomcat's CATALINA_HOME/lib directory.
>>> 
>>>>> Where is the connection pool defined? In the Context or 
>>>>> globally?
>>> 
>>>> <Resource> is defined in my webapp's context.xml.
>>> 
>>> Bump.
> 
>> I hadn't forgotten this.
> 
>> Looking into this has certainly been a good refresher for JDBC 
>> driver related memory leaks.
> 
>> For the benefit of the archives: - make sure you are using the 
>> latest mysql driver
> 
> The latest MySQL driver is actually worse than the older ones.
> I've been fighting a battle with those folks to do take proper care
> of ClassLoader issues.
> 
>> - you'll need to add "com.mysql.jdbc.NonRegisteringDriver" to the
>>  JreMemoryLeakPreventionListener's classesToInitialize set
> 
> I believe this is a bad solution, but the best one given the MySQL 
> driver's poor ClassLoader handling. I am aware that the driver
> itself pins the WebappClassLoader and I have a patch for it. The
> (Tomcat) pool is still holding onto the ClassLoader, too, though.
> 
>> Also, right now, you'll need to add closeMethod="close" to the 
>> <Resource.../> definition for the DataSource. This shouldn't be 
>> necessary and I am in the process of fixing this for the next
>> 8.0.x release.
> 
> Okay, I'll check out adding the "closeMethod".

Adding the closeMethod="close" seems to remove the DBCP reference to
the ClassLoader. Excellent.

Thanks,
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
Comment: GPGTools - http://gpgtools.org

iQIcBAEBCAAGBQJUIZu4AAoJEBzwKT+lPKRYxpAQAIqX/Zud0VtpfJdjq37HVIX7
h2VbYyFUQwf0m4DZBdkG2rst6NiXROkeUOHAYnxG8XTG/TqaBiFvULt2yhwNUuFk
uWkYv/uyTPg1omUXMtet5o9ea/1St3TBeJPnC8jgZ3+jOBMIzxM0bQXhkWwPspZ/
A1Ij6JGcTChHA9X0qfD9bQw+mP9qV/zqWdY1nMXeFeBgB8wDgbGAK00Mdkn4O9jt
Vm5Fk/JUzye7LAAQzgLfDP0FjXinq0mnj0mjVt17UkYcDR9ZuxZt/pZJ7hnyR83Y
7Ani8cYrqE/vdYbXTCp+gpmVsmdpQdZ83//HjFtB1e/lgUxkgXhR7IxUVyc57CUl
8h+iD8kYno0QOw8u5Oklm2wFdPQkvsaoO3U7gITmdJSFyG1aNU+ewDCs/XHwGItK
FQFZdJlWuI6P7NgLsQTCR8JSR7mbBi4biTtxtleifGqYSTIFsMDpdmVb6cVzzVMe
dBUNRqWt91e5D+d5xAlErstDL5nVWgLu60BC2od1q/YzylcNs+OXjcaj4vdeRxVx
QVdDeJxcgW54ZZ8dDkzcvRdfE+1VzFoEdbBPzMB4dkxGoH4D2de5w6O8ErvCgoog
WT/DjZYlEPUMLh8uUkOZ1pwuzBCV9V29Nuwbe+MX7dEzxPNScT1R6fd+ZFvDvNsO
kdAa1owo470hbtd9APdO
=KjE+
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: DBCP2 holding references to WebappClassLoader; resource leak

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Mark,

On 9/23/14 5:52 AM, Mark Thomas wrote:
> On 22/09/2014 13:50, Christopher Schultz wrote:
>> Mark,
>> 
>> On 9/17/14 4:06 PM, Christopher Schultz wrote:
>>> Mark,
>> 
>>> On 9/17/14 4:02 PM, Mark Thomas wrote:
>>>> On 17/09/2014 20:55, Christopher Schultz wrote:
>>>>> All,
>>>>> 
>>>>> I'm running Tomcat 8.0.9 on Mac OS X under Oracle's Java 7
>>>>>  jdk1.7.0_65.
>>>>> 
>>>>> For a long time, I've had a cleanly reloading web
>>>>> application, meaning that after my web application is
>>>>> reloaded (say, during development), the old
>>>>> WebappClassLoader is available for GC.
>>>>> 
>>>>> After switching to Tomcat 8.x in my development
>>>>> environment, I've noticed that I can't cleanly reload
>>>>> anymore. Using YourKit, I've traced the reference to my
>>>>> WebappClassLoader to DBCP2.
>>>>> 
>>>>> I have a JNDI DataSource whose JDBC driver is loaded from 
>>>>> Tomcat's CATALINA_HOME/lib directory.
>> 
>>>> Where is the connection pool defined? In the Context or 
>>>> globally?
>> 
>>> <Resource> is defined in my webapp's context.xml.
>> 
>> Bump.
> 
> I hadn't forgotten this.
> 
> Looking into this has certainly been a good refresher for JDBC
> driver related memory leaks.
> 
> For the benefit of the archives: - make sure you are using the
> latest mysql driver

The latest MySQL driver is actually worse than the older ones. I've
been fighting a battle with those folks to do take proper care of
ClassLoader issues.

> - you'll need to add "com.mysql.jdbc.NonRegisteringDriver" to the 
> JreMemoryLeakPreventionListener's classesToInitialize set

I believe this is a bad solution, but the best one given the MySQL
driver's poor ClassLoader handling. I am aware that the driver itself
pins the WebappClassLoader and I have a patch for it. The (Tomcat)
pool is still holding onto the ClassLoader, too, though.

> Also, right now, you'll need to add closeMethod="close" to the 
> <Resource.../> definition for the DataSource. This shouldn't be 
> necessary and I am in the process of fixing this for the next 8.0.x
> release.

Okay, I'll check out adding the "closeMethod".

Thanks,
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
Comment: GPGTools - http://gpgtools.org

iQIcBAEBCAAGBQJUIYEiAAoJEBzwKT+lPKRYwssQAITKQ4trZXBdAbCLuAvvSh6E
8a4ruDc3zIYz/Tlq9PEhcvtft5ga6x1+CBJp1tlmJ7Mf8DfJhdMhlTAyQA0PYZM+
kCvG/ApeTFH+jVlk5eWhZgP44D3tUWoT7K5zFOaVjc1j6/Mc7pG5iKIuDtME+ld+
8vVFoM2g6PhTnAmUUUUwq55HrXBlPZf6eLnkzw7WldMP6JnaAieU3mDUAzLO0osK
s22FbFpTJiRzjH6HGdb1ns7fdE4LBqqZlH+1gE0L6t55hwzDiKtceokyibsdhD9y
M1RkTrWjCuD1XXXHnvhj6xONjFslw3jYGsPBMeCiMv4nUj5256DU5thnD5KfPPd1
M30t6btvcviqPmkDcGL++aaJqkQ1YeKOVVv8qcWBh43+7if21SnlHcQJidTbNkY/
L2I3+Hk5vSK/ivB98VJk8CtnoPoI4GUJB9/M5GqBIBokClbWijfSOA3/NAgyicl3
pKlXayMiNy9d4jOjNI3ryHjZYJMIlrqtXER5aDXhUvaogePSPKNG/RgS/W9HzinU
ZqtETHH7xuR9MosHykDOEnjSCPcJ+n/R3Aw3cyrAYjFDxRh0268Lqhp3RCuAS0r3
TtBLHTQug6s0/jgoBvx+Tj63+NSJd3npHr+2JcMrzSDPLVPBFjd3mPYkKYdsxtCa
z3izg0tlgnuqQ9WnUvMs
=XsRS
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: DBCP2 holding references to WebappClassLoader; resource leak

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Mark,

On 9/23/14 9:48 AM, Mark Thomas wrote:
> On 23/09/2014 10:52, Mark Thomas wrote:
>> On 22/09/2014 13:50, Christopher Schultz wrote:
>>> Mark,
>>> 
>>> On 9/17/14 4:06 PM, Christopher Schultz wrote:
>>>> Mark,
>>> 
>>>> On 9/17/14 4:02 PM, Mark Thomas wrote:
>>>>> On 17/09/2014 20:55, Christopher Schultz wrote:
>>>>>> All,
>>>>>> 
>>>>>> I'm running Tomcat 8.0.9 on Mac OS X under Oracle's Java
>>>>>> 7 jdk1.7.0_65.
>>>>>> 
>>>>>> For a long time, I've had a cleanly reloading web
>>>>>> application, meaning that after my web application is
>>>>>> reloaded (say, during development), the old
>>>>>> WebappClassLoader is available for GC.
>>>>>> 
>>>>>> After switching to Tomcat 8.x in my development
>>>>>> environment, I've noticed that I can't cleanly reload
>>>>>> anymore. Using YourKit, I've traced the reference to my
>>>>>> WebappClassLoader to DBCP2.
>>>>>> 
>>>>>> I have a JNDI DataSource whose JDBC driver is loaded from
>>>>>>  Tomcat's CATALINA_HOME/lib directory.
>>> 
>>>>> Where is the connection pool defined? In the Context or 
>>>>> globally?
>>> 
>>>> <Resource> is defined in my webapp's context.xml.
>>> 
>>> Bump.
>> 
>> I hadn't forgotten this.
>> 
>> Looking into this has certainly been a good refresher for JDBC
>> driver related memory leaks.
>> 
>> For the benefit of the archives: - make sure you are using the
>> latest mysql driver - you'll need to add
>> "com.mysql.jdbc.NonRegisteringDriver" to the 
>> JreMemoryLeakPreventionListener's classesToInitialize set
>> 
>> Also, right now, you'll need to add closeMethod="close" to the 
>> <Resource.../> definition for the DataSource. This shouldn't be 
>> necessary and I am in the process of fixing this for the next
>> 8.0.x release.
> 
> All fixed. And some additional fixes from Commons Pool2/DBCP2
> pulled in as well for 8.0.13 onwards.

Even better!

Now, to convince MySQL to manage their ClassLoaders properly...

Thanks,
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
Comment: GPGTools - http://gpgtools.org

iQIcBAEBCAAGBQJUIZvnAAoJEBzwKT+lPKRY19oQALbcyWIUHiETTZbiOfDXK/Df
U1qDRLeqZBwdEArcoFj5tI/AP5N3GP6BlZA71F4cBQp+0OnO4eKLhlM6NBXXK2zF
9t/6bvdGOvmbYK7LXDOImGcJGXbk5Gf11eTSRlj11Dhobcycf/gn5KUb9sFtRa96
lMnUm/G1n/1q2QTEAXInUoPNBllyuNRCD0R2FjqA73OPoiaOdkEn/T2pVokD2MB5
ztaBiRqmNjk5GISkHruqoJThEh79gsqu2tMCLWKkEBbnHcGxRWYMLBhI4WFMP2w/
HtesSA+MOT6G/bKbdKVvq+ZgAnsdkxprsFw9u2FXLML1ziiRUkaECI8c+jUBmlLn
NkM4OF6YHfvk1tMYw6npaRICmXXz+n/IXiWcCdzgP2VZ43fLqPudEbTXbl2Mre74
GQYN0wyZrr3a1CwXN/IN01cvbbgUxWrsYtI1CjtJgskzqGquinQym9jtu7SiE4/H
6QOxYpdZzKbtAZp/jwXN/SfOP/ANdaFNnx27MmayGW0iVr5VH6XoI2tU1Mjh4P40
3jXFkCAfr/rzwrCD1kzKlinTt7VFXw+dqYRS65KQViHwAqDQPU+PxVn0FtRa/gCI
WpbW3Wfs22KdaDB+NclY7ZrvENZV19usb4V2I4f2ELnbTodJHOfAHOVeNhZbRnfJ
e9dXFTVjCoCtUcARY5rb
=LY2D
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: DBCP2 holding references to WebappClassLoader; resource leak

Posted by Mark Thomas <ma...@apache.org>.
On 23/09/2014 10:52, Mark Thomas wrote:
> On 22/09/2014 13:50, Christopher Schultz wrote:
>> Mark,
>>
>> On 9/17/14 4:06 PM, Christopher Schultz wrote:
>>> Mark,
>>
>>> On 9/17/14 4:02 PM, Mark Thomas wrote:
>>>> On 17/09/2014 20:55, Christopher Schultz wrote:
>>>>> All,
>>>>>
>>>>> I'm running Tomcat 8.0.9 on Mac OS X under Oracle's Java 7 
>>>>> jdk1.7.0_65.
>>>>>
>>>>> For a long time, I've had a cleanly reloading web application, 
>>>>> meaning that after my web application is reloaded (say, during 
>>>>> development), the old WebappClassLoader is available for GC.
>>>>>
>>>>> After switching to Tomcat 8.x in my development environment, 
>>>>> I've noticed that I can't cleanly reload anymore. Using
>>>>> YourKit, I've traced the reference to my WebappClassLoader to
>>>>> DBCP2.
>>>>>
>>>>> I have a JNDI DataSource whose JDBC driver is loaded from 
>>>>> Tomcat's CATALINA_HOME/lib directory.
>>
>>>> Where is the connection pool defined? In the Context or
>>>> globally?
>>
>>> <Resource> is defined in my webapp's context.xml.
>>
>> Bump.
> 
> I hadn't forgotten this.
> 
> Looking into this has certainly been a good refresher for JDBC driver
> related memory leaks.
> 
> For the benefit of the archives:
> - make sure you are using the latest mysql driver
> - you'll need to add "com.mysql.jdbc.NonRegisteringDriver" to the
> JreMemoryLeakPreventionListener's classesToInitialize set
> 
> Also, right now, you'll need to add closeMethod="close" to the
> <Resource.../> definition for the DataSource. This shouldn't be
> necessary and I am in the process of fixing this for the next 8.0.x release.

All fixed. And some additional fixes from Commons Pool2/DBCP2 pulled in
as well for 8.0.13 onwards.

Mark


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: DBCP2 holding references to WebappClassLoader; resource leak

Posted by Mark Thomas <ma...@apache.org>.
On 22/09/2014 13:50, Christopher Schultz wrote:
> Mark,
> 
> On 9/17/14 4:06 PM, Christopher Schultz wrote:
>> Mark,
> 
>> On 9/17/14 4:02 PM, Mark Thomas wrote:
>>> On 17/09/2014 20:55, Christopher Schultz wrote:
>>>> All,
>>>>
>>>> I'm running Tomcat 8.0.9 on Mac OS X under Oracle's Java 7 
>>>> jdk1.7.0_65.
>>>>
>>>> For a long time, I've had a cleanly reloading web application, 
>>>> meaning that after my web application is reloaded (say, during 
>>>> development), the old WebappClassLoader is available for GC.
>>>>
>>>> After switching to Tomcat 8.x in my development environment, 
>>>> I've noticed that I can't cleanly reload anymore. Using
>>>> YourKit, I've traced the reference to my WebappClassLoader to
>>>> DBCP2.
>>>>
>>>> I have a JNDI DataSource whose JDBC driver is loaded from 
>>>> Tomcat's CATALINA_HOME/lib directory.
> 
>>> Where is the connection pool defined? In the Context or
>>> globally?
> 
>> <Resource> is defined in my webapp's context.xml.
> 
> Bump.

I hadn't forgotten this.

Looking into this has certainly been a good refresher for JDBC driver
related memory leaks.

For the benefit of the archives:
- make sure you are using the latest mysql driver
- you'll need to add "com.mysql.jdbc.NonRegisteringDriver" to the
JreMemoryLeakPreventionListener's classesToInitialize set

Also, right now, you'll need to add closeMethod="close" to the
<Resource.../> definition for the DataSource. This shouldn't be
necessary and I am in the process of fixing this for the next 8.0.x release.

Mark

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: DBCP2 holding references to WebappClassLoader; resource leak

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Mark,

On 9/17/14 4:06 PM, Christopher Schultz wrote:
> Mark,
> 
> On 9/17/14 4:02 PM, Mark Thomas wrote:
>> On 17/09/2014 20:55, Christopher Schultz wrote:
>>> All,
>>> 
>>> I'm running Tomcat 8.0.9 on Mac OS X under Oracle's Java 7 
>>> jdk1.7.0_65.
>>> 
>>> For a long time, I've had a cleanly reloading web application, 
>>> meaning that after my web application is reloaded (say, during 
>>> development), the old WebappClassLoader is available for GC.
>>> 
>>> After switching to Tomcat 8.x in my development environment, 
>>> I've noticed that I can't cleanly reload anymore. Using
>>> YourKit, I've traced the reference to my WebappClassLoader to
>>> DBCP2.
>>> 
>>> I have a JNDI DataSource whose JDBC driver is loaded from 
>>> Tomcat's CATALINA_HOME/lib directory.
> 
>> Where is the connection pool defined? In the Context or
>> globally?
> 
> <Resource> is defined in my webapp's context.xml.

Bump.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
Comment: GPGTools - http://gpgtools.org

iQIcBAEBCAAGBQJUIBsRAAoJEBzwKT+lPKRYltUP/2pGBSYaWyhrBUu4EwiBMDQu
4hkKS0G3OzqbDsWj22Wny2mLe16idsG/ugDWdhdC6u571A01aVfhkcvwvqNn4G0M
EI4FzAgpgUOkUR/s+FGruY+v5eg5Y8watIugZExPxCcxM9FwZBVXNcSZywG1L7C5
hIopw3k4sPsUbLnd6EquuBmPbM02lFEPVR9w6adcGWm8jtM+xDV9YwdO2IvcR4Mz
OhLCBXPy4vl3CDTYIEZnPb1rgAEImh0kIHXqM/Rq8Fw/csVE6U8xTfZXF7aIUrCL
KUNaIHP4wiFycQyVA7ZOo9XsWVbD7IJzVrdsaSiODa2eQgbm11lgTJznWMdiM7pc
x3cSc1pwhTcYWMnKOeGnqHnTOmZppTqki3XZgSBl4PEEy8UwL2cb11m+7LegRYeE
CMw96iPWc+W+KRe3CZ3w+LmhAMKvteKdTvRblj48r29Rf7xtMp0IPkIYCq2kSASX
wqK59bynxUtfOWiMPtpnxl739wMqmcFkDt/tx/gp5Eo86G/0QsO3OEOSCyXqHwsd
kQnYougbuzTvCOH8XxLn1ylxIsNzMro87OwXnm06VgT7xKb+ZiR/eYYEMvxq0OjS
/KywDHLgdZ3IC8rSvJ2gH1Td7dP8TXMlprnuD+jnKaDDn9D633o9GK6GagWlGcAC
RwjCqa1e3gm751H54KyP
=7thw
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: DBCP2 holding references to WebappClassLoader; resource leak

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Mark,

On 9/17/14 4:02 PM, Mark Thomas wrote:
> On 17/09/2014 20:55, Christopher Schultz wrote:
>> All,
>> 
>> I'm running Tomcat 8.0.9 on Mac OS X under Oracle's Java 7
>> jdk1.7.0_65.
>> 
>> For a long time, I've had a cleanly reloading web application,
>> meaning that after my web application is reloaded (say, during
>> development), the old WebappClassLoader is available for GC.
>> 
>> After switching to Tomcat 8.x in my development environment,
>> I've noticed that I can't cleanly reload anymore. Using YourKit,
>> I've traced the reference to my WebappClassLoader to DBCP2.
>> 
>> I have a JNDI DataSource whose JDBC driver is loaded from
>> Tomcat's CATALINA_HOME/lib directory.
> 
> Where is the connection pool defined? In the Context or globally?

<Resource> is defined in my webapp's context.xml.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
Comment: GPGTools - http://gpgtools.org

iQIcBAEBCAAGBQJUGemqAAoJEBzwKT+lPKRY33QP/2owcTjXkzXAQUeV/Plu7jQ9
vzrDxJU5MLnyH+zGwsuLq4oHt/pu1U4LvZAp8oFaOufjFx0YKA46FWO64kwWTzm5
gUm3GIs8oUooPlB8XJTjrAIb7yW2+K5xFGHLD6nu2aBTAa01Kwdwll+qSoYAinQX
37G2L4wvypxTHgYZgqxv9RvxxpZGLz5PYuVJCAfKcb0sRmW1Y1r8MxCqtzaKVsbf
E0DKBkoHSXpyEqFALu2P6UKn0Jb5xWknf4znoEHVaVtiiH2Fs7i9DXEn0dDUg1Xw
tzFmYHiicVnv0KIG1Th5j5NfelumdLN0Ypkn4xINVfapKYnOYR+Z2UcJx3yTVSo+
8uRg0RiKkqKETla7aVZ8DwwGMNXk9K1FeCaI8jhxcfmIygaABKP8HL84uE8yBMNE
41gkmWwgdYz3a3d7Ry5EC8LfX4e4azcZtyiGqFybJzJX4HCDEe7otJ8D5V3xcUPY
crUK1ueC0sxK9el/LSg49I3kid3MxJju5jF6PVSv0syJfK3b6a942VGLMS3eDozU
qG7cwCT71zTCKx+JX0m3a7bngpXUkC23TJamdg0QXLC131cz8rJo5pkn1xMjebAC
ec6Wvy/Hr37XxgA8rTaO9ncoc26CXHUE7VEqOC1Fn+Dy484YV2T9yyFD7akxYObN
+1u6Uw+pC42jHB0fq66c
=A32F
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: DBCP2 holding references to WebappClassLoader; resource leak

Posted by Mark Thomas <ma...@apache.org>.
On 17/09/2014 20:55, Christopher Schultz wrote:
> All,
> 
> I'm running Tomcat 8.0.9 on Mac OS X under Oracle's Java 7 jdk1.7.0_65.
> 
> For a long time, I've had a cleanly reloading web application, meaning
> that after my web application is reloaded (say, during development),
> the old WebappClassLoader is available for GC.
> 
> After switching to Tomcat 8.x in my development environment, I've
> noticed that I can't cleanly reload anymore. Using YourKit, I've
> traced the reference to my WebappClassLoader to DBCP2.
> 
> I have a JNDI DataSource whose JDBC driver is loaded from Tomcat's
> CATALINA_HOME/lib directory.

Where is the connection pool defined? In the Context or globally?

> It seems that org.apache.tomcat.dbcp.pool2.impl.GenericObjectPool has
> a member, factoryClassLoader, which points to my WebappClassLoader. I
> believe that it will likely retain that reference after multiple
> reloads, so I'm only leaking a single WebappClassLoader.

I think that will be a problem for global DataSource instances. I'd need
to review what the field was doing to figure out the correct fix.

Mark


> 
> I think we probably want to use the ClassLoader of the JDBC driver for
> the DBCP pool as well. Can anyone confirm that this happens to them as
> well?
> 
> Thanks,
> -chris
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: DBCP2 holding references to WebappClassLoader; resource leak

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

All,

On 9/17/14 3:55 PM, Christopher Schultz wrote:
> I'm running Tomcat 8.0.9 on Mac OS X under Oracle's Java 7
> jdk1.7.0_65.
> 
> For a long time, I've had a cleanly reloading web application,
> meaning that after my web application is reloaded (say, during
> development), the old WebappClassLoader is available for GC.
> 
> After switching to Tomcat 8.x in my development environment, I've 
> noticed that I can't cleanly reload anymore. Using YourKit, I've 
> traced the reference to my WebappClassLoader to DBCP2.
> 
> I have a JNDI DataSource whose JDBC driver is loaded from Tomcat's 
> CATALINA_HOME/lib directory.
> 
> It seems that org.apache.tomcat.dbcp.pool2.impl.GenericObjectPool
> has a member, factoryClassLoader, which points to my
> WebappClassLoader. I believe that it will likely retain that
> reference after multiple reloads, so I'm only leaking a single
> WebappClassLoader.

After a couple of re-loads, I can see that I'm getting each
WebappClassLoader pinned in memory by the same object graph. So that
means it's a pretty significant leak. I'll upgrade to 8.0.latest to be
sure I've got the best version.

Interestingly enough, GenericObjectPool contains a
"creationStackTrace" member. Here's its value for one of the instances:

java.lang.Exception
	at
org.apache.tomcat.dbcp.pool2.impl.BaseGenericObjectPool.<init>(BaseGenericObjectPool.java:134)
	at
org.apache.tomcat.dbcp.pool2.impl.GenericObjectPool.<init>(GenericObjectPool.java:104)
	at
org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createConnectionPool(BasicDataSource.java:2067)
	at
org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createDataSource(BasicDataSource.java:1919)
	at
org.apache.tomcat.dbcp.dbcp2.BasicDataSource.getLogWriter(BasicDataSource.java:1467)
	at
org.apache.tomcat.dbcp.dbcp2.BasicDataSourceFactory.createDataSource(BasicDataSourceFactory.java:439)
	at
org.apache.tomcat.dbcp.dbcp2.BasicDataSourceFactory.getObjectInstance(BasicDataSourceFactory.java:182)
	at
org.apache.naming.factory.FactoryBase.getObjectInstance(FactoryBase.java:94)
	at
javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:321)
	at org.apache.naming.NamingContext.lookup(NamingContext.java:841)
	at org.apache.naming.NamingContext.lookup(NamingContext.java:152)
	at org.apache.naming.NamingContext.lookup(NamingContext.java:829)
	at org.apache.naming.NamingContext.lookup(NamingContext.java:166)
	at
org.apache.catalina.core.NamingContextListener.addResource(NamingContextListener.java:1084)
	at
org.apache.catalina.core.NamingContextListener.createNamingContext(NamingContextListener.java:663)
	at
org.apache.catalina.core.NamingContextListener.lifecycleEvent(NamingContextListener.java:256)
	at
org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
	at
org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
	at
org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5083)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
	at
org.apache.catalina.core.StandardContext.reload(StandardContext.java:3780)
	at
org.apache.catalina.loader.WebappLoader.backgroundProcess(WebappLoader.java:293)
	at
org.apache.catalina.core.StandardContext.backgroundProcess(StandardContext.java:5539)
	at
org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1365)
	at
org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1369)
	at
org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1369)
	at
org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1345)
	at java.lang.Thread.run(Thread.java:745)

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
Comment: GPGTools - http://gpgtools.org

iQIcBAEBCAAGBQJUGel5AAoJEBzwKT+lPKRY+r4P/2Cs+2ryN/5fTOg5uJd+5aUO
XKmX95M80se7XLpFK+DHC5642/DxxMN4Ck4v4D8Pupp/jxMEDPR554fmVFjGUt9p
2qwqnisydKfP28mPooxI3QUt/Ql0U/qpvXQxAFdzLohKNDeRqMKYQm9/79TcT+hs
zm8DjT+Qj2XU1tmHhNieVj1wLC50IFmzFwFcddQ8s6iHWSrD84eZnQ6Hbjju1gau
G2Sgxe3mBILuRxFsfSfwTVVCG6xCK3DCn+V6oaRWpwy2R5gG5vh3WI1goAak10Dn
z7Bq9zoX8jRObYveFoUQ2M0e/5MmxifbiY3IC1BYpr9bKLcCYNJWK01wKWWHSDR4
I8RPiufBoOq12KX+1Grlzb2P8wt1Ih6DeMb1+qpiWfa1e+tlfFO4iCIofXu2+G21
VuzcI30uERcD3pChUMnRcPL5ygtOhZvO24tSA3dm5ddwzvvuFyovavdyAT71tugI
+m1KQB+Vz3LR/SjSPNGLZ1BlqSjkenbti7LPsd4Kpld7ZK7oJYr8jgNJJwy5MbmS
/YZPulFAMvOhwKVVBgdI4VFfjOtey7rLiXiOSnDlVrmHfvHwNkyEKQHsvvTomsSF
3kgZ4HRh2OSKE5Y1RlyQlPuPafApvof34vDtzK1AwcrVIvQPmVNycgc4zfLTrM81
MRo3kI6jY5Fa2gAD16uq
=A+zu
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org