[jira] Created: (DBCP-294) Memory leak in XA Implementation

29 messages Options
Embed this post
Permalink
1 2
JIRA jira@apache.org

[jira] Created: (DBCP-294) Memory leak in XA Implementation

Reply Threaded More More options
Print post
Permalink
Memory leak in XA Implementation
--------------------------------

                 Key: DBCP-294
                 URL: https://issues.apache.org/jira/browse/DBCP-294
             Project: Commons Dbcp
          Issue Type: Bug
    Affects Versions: 1.3, 1.4, 2.0
         Environment: JDK5, Oracle 10G
            Reporter: Philippe Mouawad
            Priority: Critical


Hello,
We are been using Ofbiz with DBCP based implementation.
Ofbiz uses a Head revision of DBCP (package org.apache.commons.dbcp.managed is the same as current TRUNK) and geronimo-transaction-1.0.

We are having recurrent OutOfMemory which occur on a 2 days basis.
I analyzed the Heap Dump and I think have found the source of the problem:
The Heap Dump shows a Retained Heap of 400Mo by org.apache.commons.dbcp.managed.TransactionRegistry#xaResources field.

After analyzing more deeply, the leak seems to come from what is stored in xaResources through
xaResources.put(connection, xaResource);

Values inside weak Hash map  will never be removed since XAResource holds a STRONG reference on key (connection) through:
org.apache.commons.dbcp.managed.LocalXAConnectionFactory$LocalXAResource through:
public LocalXAResource(Connection localTransaction) {
            this.connection = localTransaction;
        }




--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

JIRA jira@apache.org

[jira] Updated: (DBCP-294) Memory leak in XA Implementation

Reply Threaded More More options
Print post
Permalink

     [ https://issues.apache.org/jira/browse/DBCP-294?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Philippe Mouawad updated DBCP-294:
----------------------------------

    Description:
Hello,
We are been using Ofbiz with DBCP based implementation.
Ofbiz uses a Head revision of DBCP (package org.apache.commons.dbcp.managed is the same as current TRUNK) and geronimo-transaction-1.0.

We are having recurrent OutOfMemory which occur on a 2 days basis.
I analyzed the Heap Dump and I think have found the source of the problem:
The Heap Dump shows a Retained Heap of 400Mo by org.apache.commons.dbcp.managed.TransactionRegistry#xaResources field.

After analyzing more deeply, the leak seems to come from what is stored in xaResources through
xaResources.put(connection, xaResource);

Values inside weak Hash map  will never be removed since XAResource holds a STRONG reference on key (connection) through:
org.apache.commons.dbcp.managed.LocalXAConnectionFactory$LocalXAResource through:
public LocalXAResource(Connection localTransaction) {
            this.connection = localTransaction;
        }


www.ubik-ingenierie.com

  was:
Hello,
We are been using Ofbiz with DBCP based implementation.
Ofbiz uses a Head revision of DBCP (package org.apache.commons.dbcp.managed is the same as current TRUNK) and geronimo-transaction-1.0.

We are having recurrent OutOfMemory which occur on a 2 days basis.
I analyzed the Heap Dump and I think have found the source of the problem:
The Heap Dump shows a Retained Heap of 400Mo by org.apache.commons.dbcp.managed.TransactionRegistry#xaResources field.

After analyzing more deeply, the leak seems to come from what is stored in xaResources through
xaResources.put(connection, xaResource);

Values inside weak Hash map  will never be removed since XAResource holds a STRONG reference on key (connection) through:
org.apache.commons.dbcp.managed.LocalXAConnectionFactory$LocalXAResource through:
public LocalXAResource(Connection localTransaction) {
            this.connection = localTransaction;
        }





> Memory leak in XA Implementation
> --------------------------------
>
>                 Key: DBCP-294
>                 URL: https://issues.apache.org/jira/browse/DBCP-294
>             Project: Commons Dbcp
>          Issue Type: Bug
>    Affects Versions: 1.3, 1.4, 2.0
>         Environment: JDK5, Oracle 10G
>            Reporter: Philippe Mouawad
>            Priority: Critical
>
> Hello,
> We are been using Ofbiz with DBCP based implementation.
> Ofbiz uses a Head revision of DBCP (package org.apache.commons.dbcp.managed is the same as current TRUNK) and geronimo-transaction-1.0.
> We are having recurrent OutOfMemory which occur on a 2 days basis.
> I analyzed the Heap Dump and I think have found the source of the problem:
> The Heap Dump shows a Retained Heap of 400Mo by org.apache.commons.dbcp.managed.TransactionRegistry#xaResources field.
> After analyzing more deeply, the leak seems to come from what is stored in xaResources through
> xaResources.put(connection, xaResource);
> Values inside weak Hash map  will never be removed since XAResource holds a STRONG reference on key (connection) through:
> org.apache.commons.dbcp.managed.LocalXAConnectionFactory$LocalXAResource through:
> public LocalXAResource(Connection localTransaction) {
>             this.connection = localTransaction;
>         }
> www.ubik-ingenierie.com

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

JIRA jira@apache.org

[jira] Updated: (DBCP-294) Memory leak in XA Implementation

Reply Threaded More More options
Print post
Permalink
In reply to this post by JIRA jira@apache.org

     [ https://issues.apache.org/jira/browse/DBCP-294?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Philippe Mouawad updated DBCP-294:
----------------------------------

    Description:
Hello,
We are been using Ofbiz with DBCP based implementation.
Ofbiz uses a Head revision of DBCP (package org.apache.commons.dbcp.managed is the same as current TRUNK) and geronimo-transaction-1.0.

We are having recurrent OutOfMemory which occur on a 2 days basis.
I analyzed the Heap Dump and I think have found the source of the problem:
The Heap Dump shows a Retained Heap of 400Mo by org.apache.commons.dbcp.managed.TransactionRegistry#xaResources field.

After analyzing more deeply, the leak seems to come from what is stored in xaResources through
xaResources.put(connection, xaResource);

Values inside weak Hash map  will never be removed since XAResource holds a STRONG reference on key (connection) through:
org.apache.commons.dbcp.managed.LocalXAConnectionFactory$LocalXAResource through:
public LocalXAResource(Connection localTransaction) {
            this.connection = localTransaction;
        }

Philippe Mouawad
http://www.ubik-ingenierie.com

  was:
Hello,
We are been using Ofbiz with DBCP based implementation.
Ofbiz uses a Head revision of DBCP (package org.apache.commons.dbcp.managed is the same as current TRUNK) and geronimo-transaction-1.0.

We are having recurrent OutOfMemory which occur on a 2 days basis.
I analyzed the Heap Dump and I think have found the source of the problem:
The Heap Dump shows a Retained Heap of 400Mo by org.apache.commons.dbcp.managed.TransactionRegistry#xaResources field.

After analyzing more deeply, the leak seems to come from what is stored in xaResources through
xaResources.put(connection, xaResource);

Values inside weak Hash map  will never be removed since XAResource holds a STRONG reference on key (connection) through:
org.apache.commons.dbcp.managed.LocalXAConnectionFactory$LocalXAResource through:
public LocalXAResource(Connection localTransaction) {
            this.connection = localTransaction;
        }


www.ubik-ingenierie.com


> Memory leak in XA Implementation
> --------------------------------
>
>                 Key: DBCP-294
>                 URL: https://issues.apache.org/jira/browse/DBCP-294
>             Project: Commons Dbcp
>          Issue Type: Bug
>    Affects Versions: 1.3, 1.4, 2.0
>         Environment: JDK5, Oracle 10G
>            Reporter: Philippe Mouawad
>            Priority: Critical
>
> Hello,
> We are been using Ofbiz with DBCP based implementation.
> Ofbiz uses a Head revision of DBCP (package org.apache.commons.dbcp.managed is the same as current TRUNK) and geronimo-transaction-1.0.
> We are having recurrent OutOfMemory which occur on a 2 days basis.
> I analyzed the Heap Dump and I think have found the source of the problem:
> The Heap Dump shows a Retained Heap of 400Mo by org.apache.commons.dbcp.managed.TransactionRegistry#xaResources field.
> After analyzing more deeply, the leak seems to come from what is stored in xaResources through
> xaResources.put(connection, xaResource);
> Values inside weak Hash map  will never be removed since XAResource holds a STRONG reference on key (connection) through:
> org.apache.commons.dbcp.managed.LocalXAConnectionFactory$LocalXAResource through:
> public LocalXAResource(Connection localTransaction) {
>             this.connection = localTransaction;
>         }
> Philippe Mouawad
> http://www.ubik-ingenierie.com

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

JIRA jira@apache.org

[jira] Commented: (DBCP-294) Memory leak in XA Implementation

Reply Threaded More More options
Print post
Permalink
In reply to this post by JIRA jira@apache.org

    [ https://issues.apache.org/jira/browse/DBCP-294?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12718871#action_12718871 ]

Philippe Mouawad commented on DBCP-294:
---------------------------------------

My patch proposition would be:
    public synchronized void registerConnection(Connection connection, XAResource xaResource) {
        if (connection == null) throw new NullPointerException("connection is null");
        if (xaResource == null) throw new NullPointerException("xaResource is null");
        xaResources.put(connection, new WeakReference(xaResource));
    }


When a Transaction completes:
1) XA Manager will remove strong reference on xaResource.
2) WeakReference can then be garbage collected
3) Finally key will be removed

Philippe Mouawad
http://www.ubik-ingenierie.com

> Memory leak in XA Implementation
> --------------------------------
>
>                 Key: DBCP-294
>                 URL: https://issues.apache.org/jira/browse/DBCP-294
>             Project: Commons Dbcp
>          Issue Type: Bug
>    Affects Versions: 1.3, 1.4, 2.0
>         Environment: JDK5, Oracle 10G
>            Reporter: Philippe Mouawad
>            Priority: Critical
>
> Hello,
> We are been using Ofbiz with DBCP based implementation.
> Ofbiz uses a Head revision of DBCP (package org.apache.commons.dbcp.managed is the same as current TRUNK) and geronimo-transaction-1.0.
> We are having recurrent OutOfMemory which occur on a 2 days basis.
> I analyzed the Heap Dump and I think have found the source of the problem:
> The Heap Dump shows a Retained Heap of 400Mo by org.apache.commons.dbcp.managed.TransactionRegistry#xaResources field.
> After analyzing more deeply, the leak seems to come from what is stored in xaResources through
> xaResources.put(connection, xaResource);
> Values inside weak Hash map  will never be removed since XAResource holds a STRONG reference on key (connection) through:
> org.apache.commons.dbcp.managed.LocalXAConnectionFactory$LocalXAResource through:
> public LocalXAResource(Connection localTransaction) {
>             this.connection = localTransaction;
>         }
> Found in WeakHashMap javadoc:
> Implementation note: The value objects in a WeakHashMap are held by ordinary strong references. >>>>>>>>>>>>>Thus care should be taken to ensure that value objects do not strongly refer to their own keys <<<<<<<<, either directly or indirectly, since that will prevent the keys from being discarded. Note that a value object may refer indirectly to its key via the WeakHashMap itself; that is, a value object may strongly refer to some other key object whose associated value object, in turn, strongly refers to the key of the first value object. One way to deal with this is to wrap values themselves within WeakReferences before inserting, as in: m.put(key, new WeakReference(value)), and then unwrapping upon each get.
> Philippe Mouawad
> http://www.ubik-ingenierie.com

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

JIRA jira@apache.org

[jira] Updated: (DBCP-294) Memory leak in XA Implementation

Reply Threaded More More options
Print post
Permalink
In reply to this post by JIRA jira@apache.org

     [ https://issues.apache.org/jira/browse/DBCP-294?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Philippe Mouawad updated DBCP-294:
----------------------------------

    Description:
Hello,
We are been using Ofbiz with DBCP based implementation.
Ofbiz uses a Head revision of DBCP (package org.apache.commons.dbcp.managed is the same as current TRUNK) and geronimo-transaction-1.0.

We are having recurrent OutOfMemory which occur on a 2 days basis.
I analyzed the Heap Dump and I think have found the source of the problem:
The Heap Dump shows a Retained Heap of 400Mo by org.apache.commons.dbcp.managed.TransactionRegistry#xaResources field.

After analyzing more deeply, the leak seems to come from what is stored in xaResources through
xaResources.put(connection, xaResource);

Values inside weak Hash map  will never be removed since XAResource holds a STRONG reference on key (connection) through:
org.apache.commons.dbcp.managed.LocalXAConnectionFactory$LocalXAResource through:
public LocalXAResource(Connection localTransaction) {
            this.connection = localTransaction;
        }


Found in WeakHashMap javadoc:
Implementation note: The value objects in a WeakHashMap are held by ordinary strong references. >>>>>>>>>>>>>Thus care should be taken to ensure that value objects do not strongly refer to their own keys <<<<<<<<, either directly or indirectly, since that will prevent the keys from being discarded. Note that a value object may refer indirectly to its key via the WeakHashMap itself; that is, a value object may strongly refer to some other key object whose associated value object, in turn, strongly refers to the key of the first value object. One way to deal with this is to wrap values themselves within WeakReferences before inserting, as in: m.put(key, new WeakReference(value)), and then unwrapping upon each get.

Philippe Mouawad
http://www.ubik-ingenierie.com

  was:
Hello,
We are been using Ofbiz with DBCP based implementation.
Ofbiz uses a Head revision of DBCP (package org.apache.commons.dbcp.managed is the same as current TRUNK) and geronimo-transaction-1.0.

We are having recurrent OutOfMemory which occur on a 2 days basis.
I analyzed the Heap Dump and I think have found the source of the problem:
The Heap Dump shows a Retained Heap of 400Mo by org.apache.commons.dbcp.managed.TransactionRegistry#xaResources field.

After analyzing more deeply, the leak seems to come from what is stored in xaResources through
xaResources.put(connection, xaResource);

Values inside weak Hash map  will never be removed since XAResource holds a STRONG reference on key (connection) through:
org.apache.commons.dbcp.managed.LocalXAConnectionFactory$LocalXAResource through:
public LocalXAResource(Connection localTransaction) {
            this.connection = localTransaction;
        }

Philippe Mouawad
http://www.ubik-ingenierie.com


> Memory leak in XA Implementation
> --------------------------------
>
>                 Key: DBCP-294
>                 URL: https://issues.apache.org/jira/browse/DBCP-294
>             Project: Commons Dbcp
>          Issue Type: Bug
>    Affects Versions: 1.3, 1.4, 2.0
>         Environment: JDK5, Oracle 10G
>            Reporter: Philippe Mouawad
>            Priority: Critical
>
> Hello,
> We are been using Ofbiz with DBCP based implementation.
> Ofbiz uses a Head revision of DBCP (package org.apache.commons.dbcp.managed is the same as current TRUNK) and geronimo-transaction-1.0.
> We are having recurrent OutOfMemory which occur on a 2 days basis.
> I analyzed the Heap Dump and I think have found the source of the problem:
> The Heap Dump shows a Retained Heap of 400Mo by org.apache.commons.dbcp.managed.TransactionRegistry#xaResources field.
> After analyzing more deeply, the leak seems to come from what is stored in xaResources through
> xaResources.put(connection, xaResource);
> Values inside weak Hash map  will never be removed since XAResource holds a STRONG reference on key (connection) through:
> org.apache.commons.dbcp.managed.LocalXAConnectionFactory$LocalXAResource through:
> public LocalXAResource(Connection localTransaction) {
>             this.connection = localTransaction;
>         }
> Found in WeakHashMap javadoc:
> Implementation note: The value objects in a WeakHashMap are held by ordinary strong references. >>>>>>>>>>>>>Thus care should be taken to ensure that value objects do not strongly refer to their own keys <<<<<<<<, either directly or indirectly, since that will prevent the keys from being discarded. Note that a value object may refer indirectly to its key via the WeakHashMap itself; that is, a value object may strongly refer to some other key object whose associated value object, in turn, strongly refers to the key of the first value object. One way to deal with this is to wrap values themselves within WeakReferences before inserting, as in: m.put(key, new WeakReference(value)), and then unwrapping upon each get.
> Philippe Mouawad
> http://www.ubik-ingenierie.com

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

JIRA jira@apache.org

[jira] Updated: (DBCP-294) Memory leak in XA Implementation

Reply Threaded More More options
Print post
Permalink
In reply to this post by JIRA jira@apache.org

     [ https://issues.apache.org/jira/browse/DBCP-294?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Philippe Mouawad updated DBCP-294:
----------------------------------

    Attachment: patch-TransactionRegistry.txt
                patch-ManagedConnection.txt

Patch to ManagedConnection and TransactionRegistry

> Memory leak in XA Implementation
> --------------------------------
>
>                 Key: DBCP-294
>                 URL: https://issues.apache.org/jira/browse/DBCP-294
>             Project: Commons Dbcp
>          Issue Type: Bug
>    Affects Versions: 1.3, 1.4, 2.0
>         Environment: JDK5, Oracle 10G
>            Reporter: Philippe Mouawad
>            Priority: Critical
>         Attachments: patch-ManagedConnection.txt, patch-TransactionRegistry.txt
>
>
> Hello,
> We are been using Ofbiz with DBCP based implementation.
> Ofbiz uses a Head revision of DBCP (package org.apache.commons.dbcp.managed is the same as current TRUNK) and geronimo-transaction-1.0.
> We are having recurrent OutOfMemory which occur on a 2 days basis.
> I analyzed the Heap Dump and I think have found the source of the problem:
> The Heap Dump shows a Retained Heap of 400Mo by org.apache.commons.dbcp.managed.TransactionRegistry#xaResources field.
> After analyzing more deeply, the leak seems to come from what is stored in xaResources through
> xaResources.put(connection, xaResource);
> Values inside weak Hash map  will never be removed since XAResource holds a STRONG reference on key (connection) through:
> org.apache.commons.dbcp.managed.LocalXAConnectionFactory$LocalXAResource through:
> public LocalXAResource(Connection localTransaction) {
>             this.connection = localTransaction;
>         }
> Found in WeakHashMap javadoc:
> Implementation note: The value objects in a WeakHashMap are held by ordinary strong references. >>>>>>>>>>>>>Thus care should be taken to ensure that value objects do not strongly refer to their own keys <<<<<<<<, either directly or indirectly, since that will prevent the keys from being discarded. Note that a value object may refer indirectly to its key via the WeakHashMap itself; that is, a value object may strongly refer to some other key object whose associated value object, in turn, strongly refers to the key of the first value object. One way to deal with this is to wrap values themselves within WeakReferences before inserting, as in: m.put(key, new WeakReference(value)), and then unwrapping upon each get.
> Philippe Mouawad
> http://www.ubik-ingenierie.com

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

JIRA jira@apache.org

[jira] Issue Comment Edited: (DBCP-294) Memory leak in XA Implementation

Reply Threaded More More options
Print post
Permalink
In reply to this post by JIRA jira@apache.org

    [ https://issues.apache.org/jira/browse/DBCP-294?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12718978#action_12718978 ]

Philippe Mouawad edited comment on DBCP-294 at 6/12/09 2:07 PM:
----------------------------------------------------------------

Please find attached 2 Patches to ManagedConnection and TransactionRegistry.

The idea is to unregister connection instead of relying on WeakHashMap release.
Release is done in transactionComplete()

Philippe Mouawad
http://www.ubik-ingenierie.com

      was (Author: pmouawad):
    Patch to ManagedConnection and TransactionRegistry
 

> Memory leak in XA Implementation
> --------------------------------
>
>                 Key: DBCP-294
>                 URL: https://issues.apache.org/jira/browse/DBCP-294
>             Project: Commons Dbcp
>          Issue Type: Bug
>    Affects Versions: 1.3, 1.4, 2.0
>         Environment: JDK5, Oracle 10G
>            Reporter: Philippe Mouawad
>            Priority: Critical
>         Attachments: patch-ManagedConnection.txt, patch-TransactionRegistry.txt
>
>
> Hello,
> We are been using Ofbiz with DBCP based implementation.
> Ofbiz uses a Head revision of DBCP (package org.apache.commons.dbcp.managed is the same as current TRUNK) and geronimo-transaction-1.0.
> We are having recurrent OutOfMemory which occur on a 2 days basis.
> I analyzed the Heap Dump and I think have found the source of the problem:
> The Heap Dump shows a Retained Heap of 400Mo by org.apache.commons.dbcp.managed.TransactionRegistry#xaResources field.
> After analyzing more deeply, the leak seems to come from what is stored in xaResources through
> xaResources.put(connection, xaResource);
> Values inside weak Hash map  will never be removed since XAResource holds a STRONG reference on key (connection) through:
> org.apache.commons.dbcp.managed.LocalXAConnectionFactory$LocalXAResource through:
> public LocalXAResource(Connection localTransaction) {
>             this.connection = localTransaction;
>         }
> Found in WeakHashMap javadoc:
> Implementation note: The value objects in a WeakHashMap are held by ordinary strong references. >>>>>>>>>>>>>Thus care should be taken to ensure that value objects do not strongly refer to their own keys <<<<<<<<, either directly or indirectly, since that will prevent the keys from being discarded. Note that a value object may refer indirectly to its key via the WeakHashMap itself; that is, a value object may strongly refer to some other key object whose associated value object, in turn, strongly refers to the key of the first value object. One way to deal with this is to wrap values themselves within WeakReferences before inserting, as in: m.put(key, new WeakReference(value)), and then unwrapping upon each get.
> Philippe Mouawad
> http://www.ubik-ingenierie.com

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

JIRA jira@apache.org

[jira] Commented: (DBCP-294) Memory leak in XA Implementation

Reply Threaded More More options
Print post
Permalink
In reply to this post by JIRA jira@apache.org

    [ https://issues.apache.org/jira/browse/DBCP-294?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12719111#action_12719111 ]

Philippe Mouawad commented on DBCP-294:
---------------------------------------

The 2 patches  are not OK.

Ends up with:
Caused by: java.sql.SQLException: Connection does not have a registered XAResource jdbc:postgresql://localhost:5432/console5, UserName=console5, PostgreSQL Native Driver
        at org.apache.commons.dbcp.managed.TransactionRegistry.getXAResource(TransactionRegistry.java:79)

Still searching

> Memory leak in XA Implementation
> --------------------------------
>
>                 Key: DBCP-294
>                 URL: https://issues.apache.org/jira/browse/DBCP-294
>             Project: Commons Dbcp
>          Issue Type: Bug
>    Affects Versions: 1.3, 1.4, 2.0
>         Environment: JDK5, Oracle 10G
>            Reporter: Philippe Mouawad
>            Priority: Critical
>         Attachments: patch-ManagedConnection.txt, patch-TransactionRegistry.txt
>
>
> Hello,
> We are been using Ofbiz with DBCP based implementation.
> Ofbiz uses a Head revision of DBCP (package org.apache.commons.dbcp.managed is the same as current TRUNK) and geronimo-transaction-1.0.
> We are having recurrent OutOfMemory which occur on a 2 days basis.
> I analyzed the Heap Dump and I think have found the source of the problem:
> The Heap Dump shows a Retained Heap of 400Mo by org.apache.commons.dbcp.managed.TransactionRegistry#xaResources field.
> After analyzing more deeply, the leak seems to come from what is stored in xaResources through
> xaResources.put(connection, xaResource);
> Values inside weak Hash map  will never be removed since XAResource holds a STRONG reference on key (connection) through:
> org.apache.commons.dbcp.managed.LocalXAConnectionFactory$LocalXAResource through:
> public LocalXAResource(Connection localTransaction) {
>             this.connection = localTransaction;
>         }
> Found in WeakHashMap javadoc:
> Implementation note: The value objects in a WeakHashMap are held by ordinary strong references. >>>>>>>>>>>>>Thus care should be taken to ensure that value objects do not strongly refer to their own keys <<<<<<<<, either directly or indirectly, since that will prevent the keys from being discarded. Note that a value object may refer indirectly to its key via the WeakHashMap itself; that is, a value object may strongly refer to some other key object whose associated value object, in turn, strongly refers to the key of the first value object. One way to deal with this is to wrap values themselves within WeakReferences before inserting, as in: m.put(key, new WeakReference(value)), and then unwrapping upon each get.
> Philippe Mouawad
> http://www.ubik-ingenierie.com

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

JIRA jira@apache.org

[jira] Updated: (DBCP-294) Memory leak in XA Implementation

Reply Threaded More More options
Print post
Permalink
In reply to this post by JIRA jira@apache.org

     [ https://issues.apache.org/jira/browse/DBCP-294?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Philippe Mouawad updated DBCP-294:
----------------------------------

    Attachment:     (was: patch-ManagedConnection.txt)

> Memory leak in XA Implementation
> --------------------------------
>
>                 Key: DBCP-294
>                 URL: https://issues.apache.org/jira/browse/DBCP-294
>             Project: Commons Dbcp
>          Issue Type: Bug
>    Affects Versions: 1.3, 1.4, 2.0
>         Environment: JDK5, Oracle 10G
>            Reporter: Philippe Mouawad
>            Priority: Critical
>         Attachments: patch-TransactionRegistry.txt, PoolableManagedConnection.java, PoolableManagedConnectionFactory.java
>
>
> Hello,
> We are been using Ofbiz with DBCP based implementation.
> Ofbiz uses a Head revision of DBCP (package org.apache.commons.dbcp.managed is the same as current TRUNK) and geronimo-transaction-1.0.
> We are having recurrent OutOfMemory which occur on a 2 days basis.
> I analyzed the Heap Dump and I think have found the source of the problem:
> The Heap Dump shows a Retained Heap of 400Mo by org.apache.commons.dbcp.managed.TransactionRegistry#xaResources field.
> After analyzing more deeply, the leak seems to come from what is stored in xaResources through
> xaResources.put(connection, xaResource);
> Values inside weak Hash map  will never be removed since XAResource holds a STRONG reference on key (connection) through:
> org.apache.commons.dbcp.managed.LocalXAConnectionFactory$LocalXAResource through:
> public LocalXAResource(Connection localTransaction) {
>             this.connection = localTransaction;
>         }
> Found in WeakHashMap javadoc:
> Implementation note: The value objects in a WeakHashMap are held by ordinary strong references. >>>>>>>>>>>>>Thus care should be taken to ensure that value objects do not strongly refer to their own keys <<<<<<<<, either directly or indirectly, since that will prevent the keys from being discarded. Note that a value object may refer indirectly to its key via the WeakHashMap itself; that is, a value object may strongly refer to some other key object whose associated value object, in turn, strongly refers to the key of the first value object. One way to deal with this is to wrap values themselves within WeakReferences before inserting, as in: m.put(key, new WeakReference(value)), and then unwrapping upon each get.
> Philippe Mouawad
> http://www.ubik-ingenierie.com

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

JIRA jira@apache.org

[jira] Commented: (DBCP-294) Memory leak in XA Implementation

Reply Threaded More More options
Print post
Permalink
In reply to this post by JIRA jira@apache.org

    [ https://issues.apache.org/jira/browse/DBCP-294?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12719267#action_12719267 ]

Philippe Mouawad commented on DBCP-294:
---------------------------------------

After investigating more deeply I understood what was happening.

1) In Ofbiz configuration the DBCP evictor Thread is configured.
2) When that thread runs, it kills down idle connection => THIS IS THE PROBLEM
3) TransactionRegistry holds a through LocalXAResource a reference on a connection created by DriverConnectionFactory
4) When evictor kill down a PoolableConnection calling reallyClose(), the underlying JDBC connection does not unregister from TransactionRegistry#xaResources provoking the leak.

I send a TestCase that reproduces the bug, here necessary elements:
Script for Postgres:

CREATE TABLE cb_memory_monitoring_info"(
mmi_id int8 PRIMARY KEY not null,
mmi_console_id varchar not null,
mmi_name varchar not null,
mmi_date timestamp not null,
mmi_value int4)


Run TestBug with:
-Dcom.sun.management.jmxremote -Xmx4m -Xms4m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=C:/temp

It will generate a heapDump after some seconds, look a TransactionRegistry#xaResources size, it will be around 110 elements


Then run TestBugPatch with:
-Dcom.sun.management.jmxremote -Xmx4m -Xms4m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=C:/temp

It will never run out of memory, TransactionRegistry#xaResources never grows over

Philippe Mouawad
http://www.ubik-ingenierie.com

> Memory leak in XA Implementation
> --------------------------------
>
>                 Key: DBCP-294
>                 URL: https://issues.apache.org/jira/browse/DBCP-294
>             Project: Commons Dbcp
>          Issue Type: Bug
>    Affects Versions: 1.3, 1.4, 2.0
>         Environment: JDK5, Oracle 10G
>            Reporter: Philippe Mouawad
>            Priority: Critical
>         Attachments: patch-TransactionRegistry.txt, PoolableManagedConnection.java, PoolableManagedConnectionFactory.java
>
>
> Hello,
> We are been using Ofbiz with DBCP based implementation.
> Ofbiz uses a Head revision of DBCP (package org.apache.commons.dbcp.managed is the same as current TRUNK) and geronimo-transaction-1.0.
> We are having recurrent OutOfMemory which occur on a 2 days basis.
> I analyzed the Heap Dump and I think have found the source of the problem:
> The Heap Dump shows a Retained Heap of 400Mo by org.apache.commons.dbcp.managed.TransactionRegistry#xaResources field.
> After analyzing more deeply, the leak seems to come from what is stored in xaResources through
> xaResources.put(connection, xaResource);
> Values inside weak Hash map  will never be removed since XAResource holds a STRONG reference on key (connection) through:
> org.apache.commons.dbcp.managed.LocalXAConnectionFactory$LocalXAResource through:
> public LocalXAResource(Connection localTransaction) {
>             this.connection = localTransaction;
>         }
> Found in WeakHashMap javadoc:
> Implementation note: The value objects in a WeakHashMap are held by ordinary strong references. >>>>>>>>>>>>>Thus care should be taken to ensure that value objects do not strongly refer to their own keys <<<<<<<<, either directly or indirectly, since that will prevent the keys from being discarded. Note that a value object may refer indirectly to its key via the WeakHashMap itself; that is, a value object may strongly refer to some other key object whose associated value object, in turn, strongly refers to the key of the first value object. One way to deal with this is to wrap values themselves within WeakReferences before inserting, as in: m.put(key, new WeakReference(value)), and then unwrapping upon each get.
> Philippe Mouawad
> http://www.ubik-ingenierie.com

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

JIRA jira@apache.org

[jira] Updated: (DBCP-294) Memory leak in XA Implementation

Reply Threaded More More options
Print post
Permalink
In reply to this post by JIRA jira@apache.org

     [ https://issues.apache.org/jira/browse/DBCP-294?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Philippe Mouawad updated DBCP-294:
----------------------------------

    Attachment: PoolableManagedConnection.java
                PoolableManagedConnectionFactory.java

Implementations of PoolableConnectionFactory and PoolableConnection that work well with managed connections SOLVING the OOM

> Memory leak in XA Implementation
> --------------------------------
>
>                 Key: DBCP-294
>                 URL: https://issues.apache.org/jira/browse/DBCP-294
>             Project: Commons Dbcp
>          Issue Type: Bug
>    Affects Versions: 1.3, 1.4, 2.0
>         Environment: JDK5, Oracle 10G
>            Reporter: Philippe Mouawad
>            Priority: Critical
>         Attachments: patch-TransactionRegistry.txt, PoolableManagedConnection.java, PoolableManagedConnectionFactory.java
>
>
> Hello,
> We are been using Ofbiz with DBCP based implementation.
> Ofbiz uses a Head revision of DBCP (package org.apache.commons.dbcp.managed is the same as current TRUNK) and geronimo-transaction-1.0.
> We are having recurrent OutOfMemory which occur on a 2 days basis.
> I analyzed the Heap Dump and I think have found the source of the problem:
> The Heap Dump shows a Retained Heap of 400Mo by org.apache.commons.dbcp.managed.TransactionRegistry#xaResources field.
> After analyzing more deeply, the leak seems to come from what is stored in xaResources through
> xaResources.put(connection, xaResource);
> Values inside weak Hash map  will never be removed since XAResource holds a STRONG reference on key (connection) through:
> org.apache.commons.dbcp.managed.LocalXAConnectionFactory$LocalXAResource through:
> public LocalXAResource(Connection localTransaction) {
>             this.connection = localTransaction;
>         }
> Found in WeakHashMap javadoc:
> Implementation note: The value objects in a WeakHashMap are held by ordinary strong references. >>>>>>>>>>>>>Thus care should be taken to ensure that value objects do not strongly refer to their own keys <<<<<<<<, either directly or indirectly, since that will prevent the keys from being discarded. Note that a value object may refer indirectly to its key via the WeakHashMap itself; that is, a value object may strongly refer to some other key object whose associated value object, in turn, strongly refers to the key of the first value object. One way to deal with this is to wrap values themselves within WeakReferences before inserting, as in: m.put(key, new WeakReference(value)), and then unwrapping upon each get.
> Philippe Mouawad
> http://www.ubik-ingenierie.com

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

JIRA jira@apache.org

[jira] Updated: (DBCP-294) Memory leak in XA Implementation

Reply Threaded More More options
Print post
Permalink
In reply to this post by JIRA jira@apache.org

     [ https://issues.apache.org/jira/browse/DBCP-294?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Philippe Mouawad updated DBCP-294:
----------------------------------

    Attachment: Test.zip

Test case

> Memory leak in XA Implementation
> --------------------------------
>
>                 Key: DBCP-294
>                 URL: https://issues.apache.org/jira/browse/DBCP-294
>             Project: Commons Dbcp
>          Issue Type: Bug
>    Affects Versions: 1.3, 1.4, 2.0
>         Environment: JDK5, Oracle 10G
>            Reporter: Philippe Mouawad
>            Priority: Critical
>         Attachments: patch-TransactionRegistry.txt, PoolableManagedConnection.java, PoolableManagedConnectionFactory.java, Test.zip
>
>
> Hello,
> We are been using Ofbiz with DBCP based implementation.
> Ofbiz uses a Head revision of DBCP (package org.apache.commons.dbcp.managed is the same as current TRUNK) and geronimo-transaction-1.0.
> We are having recurrent OutOfMemory which occur on a 2 days basis.
> I analyzed the Heap Dump and I think have found the source of the problem:
> The Heap Dump shows a Retained Heap of 400Mo by org.apache.commons.dbcp.managed.TransactionRegistry#xaResources field.
> After analyzing more deeply, the leak seems to come from what is stored in xaResources through
> xaResources.put(connection, xaResource);
> Values inside weak Hash map  will never be removed since XAResource holds a STRONG reference on key (connection) through:
> org.apache.commons.dbcp.managed.LocalXAConnectionFactory$LocalXAResource through:
> public LocalXAResource(Connection localTransaction) {
>             this.connection = localTransaction;
>         }
> Found in WeakHashMap javadoc:
> Implementation note: The value objects in a WeakHashMap are held by ordinary strong references. >>>>>>>>>>>>>Thus care should be taken to ensure that value objects do not strongly refer to their own keys <<<<<<<<, either directly or indirectly, since that will prevent the keys from being discarded. Note that a value object may refer indirectly to its key via the WeakHashMap itself; that is, a value object may strongly refer to some other key object whose associated value object, in turn, strongly refers to the key of the first value object. One way to deal with this is to wrap values themselves within WeakReferences before inserting, as in: m.put(key, new WeakReference(value)), and then unwrapping upon each get.
> Philippe Mouawad
> http://www.ubik-ingenierie.com

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

JIRA jira@apache.org

[jira] Updated: (DBCP-294) Memory leak in XA Implementation

Reply Threaded More More options
Print post
Permalink
In reply to this post by JIRA jira@apache.org

     [ https://issues.apache.org/jira/browse/DBCP-294?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Philippe Mouawad updated DBCP-294:
----------------------------------

    Comment: was deleted

(was: The 2 patches  are not OK.

Ends up with:
Caused by: java.sql.SQLException: Connection does not have a registered XAResource jdbc:postgresql://localhost:5432/console5, UserName=console5, PostgreSQL Native Driver
        at org.apache.commons.dbcp.managed.TransactionRegistry.getXAResource(TransactionRegistry.java:79)

Still searching)

> Memory leak in XA Implementation
> --------------------------------
>
>                 Key: DBCP-294
>                 URL: https://issues.apache.org/jira/browse/DBCP-294
>             Project: Commons Dbcp
>          Issue Type: Bug
>    Affects Versions: 1.3, 1.4, 2.0
>         Environment: JDK5, Oracle 10G
>            Reporter: Philippe Mouawad
>            Priority: Critical
>         Attachments: patch-TransactionRegistry.txt, PoolableManagedConnection.java, PoolableManagedConnectionFactory.java, Test.zip
>
>
> Hello,
> We are been using Ofbiz with DBCP based implementation.
> Ofbiz uses a Head revision of DBCP (package org.apache.commons.dbcp.managed is the same as current TRUNK) and geronimo-transaction-1.0.
> We are having recurrent OutOfMemory which occur on a 2 days basis.
> I analyzed the Heap Dump and I think have found the source of the problem:
> The Heap Dump shows a Retained Heap of 400Mo by org.apache.commons.dbcp.managed.TransactionRegistry#xaResources field.
> After analyzing more deeply, the leak seems to come from what is stored in xaResources through
> xaResources.put(connection, xaResource);
> Values inside weak Hash map  will never be removed since XAResource holds a STRONG reference on key (connection) through:
> org.apache.commons.dbcp.managed.LocalXAConnectionFactory$LocalXAResource through:
> public LocalXAResource(Connection localTransaction) {
>             this.connection = localTransaction;
>         }
> Found in WeakHashMap javadoc:
> Implementation note: The value objects in a WeakHashMap are held by ordinary strong references. >>>>>>>>>>>>>Thus care should be taken to ensure that value objects do not strongly refer to their own keys <<<<<<<<, either directly or indirectly, since that will prevent the keys from being discarded. Note that a value object may refer indirectly to its key via the WeakHashMap itself; that is, a value object may strongly refer to some other key object whose associated value object, in turn, strongly refers to the key of the first value object. One way to deal with this is to wrap values themselves within WeakReferences before inserting, as in: m.put(key, new WeakReference(value)), and then unwrapping upon each get.
> Philippe Mouawad
> http://www.ubik-ingenierie.com

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

JIRA jira@apache.org

[jira] Issue Comment Edited: (DBCP-294) Memory leak in XA Implementation

Reply Threaded More More options
Print post
Permalink
In reply to this post by JIRA jira@apache.org

    [ https://issues.apache.org/jira/browse/DBCP-294?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12718978#action_12718978 ]

Philippe Mouawad edited comment on DBCP-294 at 6/14/09 7:18 AM:
----------------------------------------------------------------

Please find attached a patch to TransactionRegistry.
The idea is to unregister connection instead of relying on WeakHashMap release.
Release will be done by PoolableConnection#reallyClose()

Philippe Mouawad
http://www.ubik-ingenierie.com

      was (Author: pmouawad):
    Please find attached 2 Patches to ManagedConnection and TransactionRegistry.

The idea is to unregister connection instead of relying on WeakHashMap release.
Release is done in transactionComplete()

Philippe Mouawad
http://www.ubik-ingenierie.com
 

> Memory leak in XA Implementation
> --------------------------------
>
>                 Key: DBCP-294
>                 URL: https://issues.apache.org/jira/browse/DBCP-294
>             Project: Commons Dbcp
>          Issue Type: Bug
>    Affects Versions: 1.3, 1.4, 2.0
>         Environment: JDK5, Oracle 10G
>            Reporter: Philippe Mouawad
>            Priority: Critical
>         Attachments: patch-TransactionRegistry.txt, PoolableManagedConnection.java, PoolableManagedConnectionFactory.java, Test.zip
>
>
> Hello,
> We are been using Ofbiz with DBCP based implementation.
> Ofbiz uses a Head revision of DBCP (package org.apache.commons.dbcp.managed is the same as current TRUNK) and geronimo-transaction-1.0.
> We are having recurrent OutOfMemory which occur on a 2 days basis.
> I analyzed the Heap Dump and I think have found the source of the problem:
> The Heap Dump shows a Retained Heap of 400Mo by org.apache.commons.dbcp.managed.TransactionRegistry#xaResources field.
> After analyzing more deeply, the leak seems to come from what is stored in xaResources through
> xaResources.put(connection, xaResource);
> Values inside weak Hash map  will never be removed since XAResource holds a STRONG reference on key (connection) through:
> org.apache.commons.dbcp.managed.LocalXAConnectionFactory$LocalXAResource through:
> public LocalXAResource(Connection localTransaction) {
>             this.connection = localTransaction;
>         }
> Found in WeakHashMap javadoc:
> Implementation note: The value objects in a WeakHashMap are held by ordinary strong references. >>>>>>>>>>>>>Thus care should be taken to ensure that value objects do not strongly refer to their own keys <<<<<<<<, either directly or indirectly, since that will prevent the keys from being discarded. Note that a value object may refer indirectly to its key via the WeakHashMap itself; that is, a value object may strongly refer to some other key object whose associated value object, in turn, strongly refers to the key of the first value object. One way to deal with this is to wrap values themselves within WeakReferences before inserting, as in: m.put(key, new WeakReference(value)), and then unwrapping upon each get.
> Philippe Mouawad
> http://www.ubik-ingenierie.com

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

JIRA jira@apache.org

[jira] Issue Comment Edited: (DBCP-294) Memory leak in XA Implementation

Reply Threaded More More options
Print post
Permalink
In reply to this post by JIRA jira@apache.org

    [ https://issues.apache.org/jira/browse/DBCP-294?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12718978#action_12718978 ]

Philippe Mouawad edited comment on DBCP-294 at 6/14/09 8:03 AM:
----------------------------------------------------------------

Please find attached a patch to TransactionRegistry.
The idea is to unregister connection instead of relying on WeakHashMap release.
Release will be done by PoolableManagedConnection#reallyClose()

Philippe Mouawad
http://www.ubik-ingenierie.com

      was (Author: pmouawad):
    Please find attached a patch to TransactionRegistry.
The idea is to unregister connection instead of relying on WeakHashMap release.
Release will be done by PoolableConnection#reallyClose()

Philippe Mouawad
http://www.ubik-ingenierie.com
 

> Memory leak in XA Implementation
> --------------------------------
>
>                 Key: DBCP-294
>                 URL: https://issues.apache.org/jira/browse/DBCP-294
>             Project: Commons Dbcp
>          Issue Type: Bug
>    Affects Versions: 1.3, 1.4, 2.0
>         Environment: JDK5, Oracle 10G
>            Reporter: Philippe Mouawad
>            Priority: Critical
>         Attachments: patch-TransactionRegistry.txt, PoolableManagedConnection.java, PoolableManagedConnectionFactory.java, Test.zip
>
>
> Hello,
> We are been using Ofbiz with DBCP based implementation.
> Ofbiz uses a Head revision of DBCP (package org.apache.commons.dbcp.managed is the same as current TRUNK) and geronimo-transaction-1.0.
> We are having recurrent OutOfMemory which occur on a 2 days basis.
> I analyzed the Heap Dump and I think have found the source of the problem:
> The Heap Dump shows a Retained Heap of 400Mo by org.apache.commons.dbcp.managed.TransactionRegistry#xaResources field.
> After analyzing more deeply, the leak seems to come from what is stored in xaResources through
> xaResources.put(connection, xaResource);
> Values inside weak Hash map  will never be removed since XAResource holds a STRONG reference on key (connection) through:
> org.apache.commons.dbcp.managed.LocalXAConnectionFactory$LocalXAResource through:
> public LocalXAResource(Connection localTransaction) {
>             this.connection = localTransaction;
>         }
> Found in WeakHashMap javadoc:
> Implementation note: The value objects in a WeakHashMap are held by ordinary strong references. >>>>>>>>>>>>>Thus care should be taken to ensure that value objects do not strongly refer to their own keys <<<<<<<<, either directly or indirectly, since that will prevent the keys from being discarded. Note that a value object may refer indirectly to its key via the WeakHashMap itself; that is, a value object may strongly refer to some other key object whose associated value object, in turn, strongly refers to the key of the first value object. One way to deal with this is to wrap values themselves within WeakReferences before inserting, as in: m.put(key, new WeakReference(value)), and then unwrapping upon each get.
> Philippe Mouawad
> http://www.ubik-ingenierie.com

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

JIRA jira@apache.org

[jira] Updated: (DBCP-294) Memory leak in XA Implementation

Reply Threaded More More options
Print post
Permalink
In reply to this post by JIRA jira@apache.org

     [ https://issues.apache.org/jira/browse/DBCP-294?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Philippe Mouawad updated DBCP-294:
----------------------------------

    Attachment: PoolableManagedConnectionFactory.java
                PoolableManagedConnection.java

Moved implementations to org.apache.commons.dbcp.managed

> Memory leak in XA Implementation
> --------------------------------
>
>                 Key: DBCP-294
>                 URL: https://issues.apache.org/jira/browse/DBCP-294
>             Project: Commons Dbcp
>          Issue Type: Bug
>    Affects Versions: 1.3, 1.4, 2.0
>         Environment: JDK5, Oracle 10G
>            Reporter: Philippe Mouawad
>            Priority: Critical
>         Attachments: patch-TransactionRegistry.txt, PoolableManagedConnection.java, PoolableManagedConnectionFactory.java, Test.zip
>
>
> Hello,
> We are been using Ofbiz with DBCP based implementation.
> Ofbiz uses a Head revision of DBCP (package org.apache.commons.dbcp.managed is the same as current TRUNK) and geronimo-transaction-1.0.
> We are having recurrent OutOfMemory which occur on a 2 days basis.
> I analyzed the Heap Dump and I think have found the source of the problem:
> The Heap Dump shows a Retained Heap of 400Mo by org.apache.commons.dbcp.managed.TransactionRegistry#xaResources field.
> After analyzing more deeply, the leak seems to come from what is stored in xaResources through
> xaResources.put(connection, xaResource);
> Values inside weak Hash map  will never be removed since XAResource holds a STRONG reference on key (connection) through:
> org.apache.commons.dbcp.managed.LocalXAConnectionFactory$LocalXAResource through:
> public LocalXAResource(Connection localTransaction) {
>             this.connection = localTransaction;
>         }
> Found in WeakHashMap javadoc:
> Implementation note: The value objects in a WeakHashMap are held by ordinary strong references. >>>>>>>>>>>>>Thus care should be taken to ensure that value objects do not strongly refer to their own keys <<<<<<<<, either directly or indirectly, since that will prevent the keys from being discarded. Note that a value object may refer indirectly to its key via the WeakHashMap itself; that is, a value object may strongly refer to some other key object whose associated value object, in turn, strongly refers to the key of the first value object. One way to deal with this is to wrap values themselves within WeakReferences before inserting, as in: m.put(key, new WeakReference(value)), and then unwrapping upon each get.
> Philippe Mouawad
> http://www.ubik-ingenierie.com

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

JIRA jira@apache.org

[jira] Updated: (DBCP-294) Memory leak in XA Implementation

Reply Threaded More More options
Print post
Permalink
In reply to this post by JIRA jira@apache.org

     [ https://issues.apache.org/jira/browse/DBCP-294?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Philippe Mouawad updated DBCP-294:
----------------------------------

    Attachment:     (was: PoolableManagedConnectionFactory.java)

> Memory leak in XA Implementation
> --------------------------------
>
>                 Key: DBCP-294
>                 URL: https://issues.apache.org/jira/browse/DBCP-294
>             Project: Commons Dbcp
>          Issue Type: Bug
>    Affects Versions: 1.3, 1.4, 2.0
>         Environment: JDK5, Oracle 10G
>            Reporter: Philippe Mouawad
>            Priority: Critical
>         Attachments: patch-TransactionRegistry.txt, PoolableManagedConnection.java, PoolableManagedConnectionFactory.java, Test.zip
>
>
> Hello,
> We are been using Ofbiz with DBCP based implementation.
> Ofbiz uses a Head revision of DBCP (package org.apache.commons.dbcp.managed is the same as current TRUNK) and geronimo-transaction-1.0.
> We are having recurrent OutOfMemory which occur on a 2 days basis.
> I analyzed the Heap Dump and I think have found the source of the problem:
> The Heap Dump shows a Retained Heap of 400Mo by org.apache.commons.dbcp.managed.TransactionRegistry#xaResources field.
> After analyzing more deeply, the leak seems to come from what is stored in xaResources through
> xaResources.put(connection, xaResource);
> Values inside weak Hash map  will never be removed since XAResource holds a STRONG reference on key (connection) through:
> org.apache.commons.dbcp.managed.LocalXAConnectionFactory$LocalXAResource through:
> public LocalXAResource(Connection localTransaction) {
>             this.connection = localTransaction;
>         }
> Found in WeakHashMap javadoc:
> Implementation note: The value objects in a WeakHashMap are held by ordinary strong references. >>>>>>>>>>>>>Thus care should be taken to ensure that value objects do not strongly refer to their own keys <<<<<<<<, either directly or indirectly, since that will prevent the keys from being discarded. Note that a value object may refer indirectly to its key via the WeakHashMap itself; that is, a value object may strongly refer to some other key object whose associated value object, in turn, strongly refers to the key of the first value object. One way to deal with this is to wrap values themselves within WeakReferences before inserting, as in: m.put(key, new WeakReference(value)), and then unwrapping upon each get.
> Philippe Mouawad
> http://www.ubik-ingenierie.com

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

JIRA jira@apache.org

[jira] Updated: (DBCP-294) Memory leak in XA Implementation

Reply Threaded More More options
Print post
Permalink
In reply to this post by JIRA jira@apache.org

     [ https://issues.apache.org/jira/browse/DBCP-294?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Philippe Mouawad updated DBCP-294:
----------------------------------

    Attachment:     (was: PoolableManagedConnection.java)

> Memory leak in XA Implementation
> --------------------------------
>
>                 Key: DBCP-294
>                 URL: https://issues.apache.org/jira/browse/DBCP-294
>             Project: Commons Dbcp
>          Issue Type: Bug
>    Affects Versions: 1.3, 1.4, 2.0
>         Environment: JDK5, Oracle 10G
>            Reporter: Philippe Mouawad
>            Priority: Critical
>         Attachments: patch-TransactionRegistry.txt, PoolableManagedConnection.java, PoolableManagedConnectionFactory.java, Test.zip
>
>
> Hello,
> We are been using Ofbiz with DBCP based implementation.
> Ofbiz uses a Head revision of DBCP (package org.apache.commons.dbcp.managed is the same as current TRUNK) and geronimo-transaction-1.0.
> We are having recurrent OutOfMemory which occur on a 2 days basis.
> I analyzed the Heap Dump and I think have found the source of the problem:
> The Heap Dump shows a Retained Heap of 400Mo by org.apache.commons.dbcp.managed.TransactionRegistry#xaResources field.
> After analyzing more deeply, the leak seems to come from what is stored in xaResources through
> xaResources.put(connection, xaResource);
> Values inside weak Hash map  will never be removed since XAResource holds a STRONG reference on key (connection) through:
> org.apache.commons.dbcp.managed.LocalXAConnectionFactory$LocalXAResource through:
> public LocalXAResource(Connection localTransaction) {
>             this.connection = localTransaction;
>         }
> Found in WeakHashMap javadoc:
> Implementation note: The value objects in a WeakHashMap are held by ordinary strong references. >>>>>>>>>>>>>Thus care should be taken to ensure that value objects do not strongly refer to their own keys <<<<<<<<, either directly or indirectly, since that will prevent the keys from being discarded. Note that a value object may refer indirectly to its key via the WeakHashMap itself; that is, a value object may strongly refer to some other key object whose associated value object, in turn, strongly refers to the key of the first value object. One way to deal with this is to wrap values themselves within WeakReferences before inserting, as in: m.put(key, new WeakReference(value)), and then unwrapping upon each get.
> Philippe Mouawad
> http://www.ubik-ingenierie.com

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

JIRA jira@apache.org

[jira] Updated: (DBCP-294) Memory leak in XA Implementation

Reply Threaded More More options
Print post
Permalink
In reply to this post by JIRA jira@apache.org

     [ https://issues.apache.org/jira/browse/DBCP-294?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Philippe Mouawad updated DBCP-294:
----------------------------------

    Attachment:     (was: patch-TransactionRegistry.txt)

> Memory leak in XA Implementation
> --------------------------------
>
>                 Key: DBCP-294
>                 URL: https://issues.apache.org/jira/browse/DBCP-294
>             Project: Commons Dbcp
>          Issue Type: Bug
>    Affects Versions: 1.3, 1.4, 2.0
>         Environment: JDK5, Oracle 10G
>            Reporter: Philippe Mouawad
>            Priority: Critical
>         Attachments: PoolableManagedConnection.java, PoolableManagedConnectionFactory.java, Test.zip, TransactionRegistry-patch.txt
>
>
> Hello,
> We are been using Ofbiz with DBCP based implementation.
> Ofbiz uses a Head revision of DBCP (package org.apache.commons.dbcp.managed is the same as current TRUNK) and geronimo-transaction-1.0.
> We are having recurrent OutOfMemory which occur on a 2 days basis.
> I analyzed the Heap Dump and I think have found the source of the problem:
> The Heap Dump shows a Retained Heap of 400Mo by org.apache.commons.dbcp.managed.TransactionRegistry#xaResources field.
> After analyzing more deeply, the leak seems to come from what is stored in xaResources through
> xaResources.put(connection, xaResource);
> Values inside weak Hash map  will never be removed since XAResource holds a STRONG reference on key (connection) through:
> org.apache.commons.dbcp.managed.LocalXAConnectionFactory$LocalXAResource through:
> public LocalXAResource(Connection localTransaction) {
>             this.connection = localTransaction;
>         }
> Found in WeakHashMap javadoc:
> Implementation note: The value objects in a WeakHashMap are held by ordinary strong references. >>>>>>>>>>>>>Thus care should be taken to ensure that value objects do not strongly refer to their own keys <<<<<<<<, either directly or indirectly, since that will prevent the keys from being discarded. Note that a value object may refer indirectly to its key via the WeakHashMap itself; that is, a value object may strongly refer to some other key object whose associated value object, in turn, strongly refers to the key of the first value object. One way to deal with this is to wrap values themselves within WeakReferences before inserting, as in: m.put(key, new WeakReference(value)), and then unwrapping upon each get.
> Philippe Mouawad
> http://www.ubik-ingenierie.com

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

JIRA jira@apache.org

[jira] Updated: (DBCP-294) Memory leak in XA Implementation

Reply Threaded More More options
Print post
Permalink
In reply to this post by JIRA jira@apache.org

     [ https://issues.apache.org/jira/browse/DBCP-294?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Philippe Mouawad updated DBCP-294:
----------------------------------

    Attachment: TransactionRegistry-patch.txt

Patch to TransactionRegistry

> Memory leak in XA Implementation
> --------------------------------
>
>                 Key: DBCP-294
>                 URL: https://issues.apache.org/jira/browse/DBCP-294
>             Project: Commons Dbcp
>          Issue Type: Bug
>    Affects Versions: 1.3, 1.4, 2.0
>         Environment: JDK5, Oracle 10G
>            Reporter: Philippe Mouawad
>            Priority: Critical
>         Attachments: PoolableManagedConnection.java, PoolableManagedConnectionFactory.java, Test.zip, TransactionRegistry-patch.txt
>
>
> Hello,
> We are been using Ofbiz with DBCP based implementation.
> Ofbiz uses a Head revision of DBCP (package org.apache.commons.dbcp.managed is the same as current TRUNK) and geronimo-transaction-1.0.
> We are having recurrent OutOfMemory which occur on a 2 days basis.
> I analyzed the Heap Dump and I think have found the source of the problem:
> The Heap Dump shows a Retained Heap of 400Mo by org.apache.commons.dbcp.managed.TransactionRegistry#xaResources field.
> After analyzing more deeply, the leak seems to come from what is stored in xaResources through
> xaResources.put(connection, xaResource);
> Values inside weak Hash map  will never be removed since XAResource holds a STRONG reference on key (connection) through:
> org.apache.commons.dbcp.managed.LocalXAConnectionFactory$LocalXAResource through:
> public LocalXAResource(Connection localTransaction) {
>             this.connection = localTransaction;
>         }
> Found in WeakHashMap javadoc:
> Implementation note: The value objects in a WeakHashMap are held by ordinary strong references. >>>>>>>>>>>>>Thus care should be taken to ensure that value objects do not strongly refer to their own keys <<<<<<<<, either directly or indirectly, since that will prevent the keys from being discarded. Note that a value object may refer indirectly to its key via the WeakHashMap itself; that is, a value object may strongly refer to some other key object whose associated value object, in turn, strongly refers to the key of the first value object. One way to deal with this is to wrap values themselves within WeakReferences before inserting, as in: m.put(key, new WeakReference(value)), and then unwrapping upon each get.
> Philippe Mouawad
> http://www.ubik-ingenierie.com

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

1 2