You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-dev@db.apache.org by "Knut Anders Hatlen (JIRA)" <ji...@apache.org> on 2008/10/11 19:19:44 UTC
[jira] Created: (DERBY-3909) Race condition in
NetXAResource.removeXaresFromSameRMchain()
Race condition in NetXAResource.removeXaresFromSameRMchain()
------------------------------------------------------------
Key: DERBY-3909
URL: https://issues.apache.org/jira/browse/DERBY-3909
Project: Derby
Issue Type: Bug
Components: Network Client
Affects Versions: 10.5.0.0
Reporter: Knut Anders Hatlen
Assignee: Knut Anders Hatlen
NetXAResource.removeXaresFromSameRMchain() does the following to remove a NetXAResource from what's logically a singly-linked list:
1) Mark the NetXAResource to remove with a flag (a field called ignoreMe_)
2) Synchronize on an object that protects the linked list
3) Follow the chain of next pointers in the linked list and remove the first flagged object
4) Release synchronization lock obtained in (2)
5) Clear the flag set in (1)
Now, say that two threads (T1 and T2) perform step 1 in parallel. T1 is granted the synchronization lock in (2), and T2 must wait. T1 traverses the linked list, finds the object flagged by T2 and removes it. Further T1 releases the synchronization lock and clears the flag on the object it had flagged. This is not the same object that it removed, so when T2 is granted the synchronization lock, there is no object flagged for removal. As a result, only the object T2 attempted to remove was in fact removed. The object that T1 flagged for removal is still in the linked list.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Updated: (DERBY-3909) Race condition in
NetXAResource.removeXaresFromSameRMchain()
Posted by "Knut Anders Hatlen (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/DERBY-3909?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Knut Anders Hatlen updated DERBY-3909:
--------------------------------------
Derby Info: (was: [Patch Available])
Unchecking "Patch Available" since I believe that removing the code is a better fix.
> Race condition in NetXAResource.removeXaresFromSameRMchain()
> ------------------------------------------------------------
>
> Key: DERBY-3909
> URL: https://issues.apache.org/jira/browse/DERBY-3909
> Project: Derby
> Issue Type: Bug
> Components: Network Client
> Affects Versions: 10.5.0.0
> Reporter: Knut Anders Hatlen
> Assignee: Knut Anders Hatlen
> Attachments: d3909.diff, Derby3909.java
>
>
> NetXAResource.removeXaresFromSameRMchain() does the following to remove a NetXAResource from what's logically a singly-linked list:
> 1) Mark the NetXAResource to remove with a flag (a field called ignoreMe_)
> 2) Synchronize on an object that protects the linked list
> 3) Follow the chain of next pointers in the linked list and remove the first flagged object
> 4) Release synchronization lock obtained in (2)
> 5) Clear the flag set in (1)
> Now, say that two threads (T1 and T2) perform step 1 in parallel. T1 is granted the synchronization lock in (2), and T2 must wait. T1 traverses the linked list, finds the object flagged by T2 and removes it. Further T1 releases the synchronization lock and clears the flag on the object it had flagged. This is not the same object that it removed, so when T2 is granted the synchronization lock, there is no object flagged for removal. As a result, only the object T2 attempted to remove was in fact removed. The object that T1 flagged for removal is still in the linked list.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Updated: (DERBY-3909) Race condition in
NetXAResource.removeXaresFromSameRMchain()
Posted by "Knut Anders Hatlen (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/DERBY-3909?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Knut Anders Hatlen updated DERBY-3909:
--------------------------------------
Attachment: d3909-remove.diff
Attached is a new patch (d3909-remove.diff) which removes the methods removeXaresFromSameRMchain() and initForReuse() from NetXAResource, and it also removes all the now unused variables from that class.
All the regression tests ran cleanly. The patch is ready for review.
> Race condition in NetXAResource.removeXaresFromSameRMchain()
> ------------------------------------------------------------
>
> Key: DERBY-3909
> URL: https://issues.apache.org/jira/browse/DERBY-3909
> Project: Derby
> Issue Type: Bug
> Components: Network Client
> Affects Versions: 10.5.0.0
> Reporter: Knut Anders Hatlen
> Assignee: Knut Anders Hatlen
> Attachments: d3909-remove.diff, d3909.diff, Derby3909.java
>
>
> NetXAResource.removeXaresFromSameRMchain() does the following to remove a NetXAResource from what's logically a singly-linked list:
> 1) Mark the NetXAResource to remove with a flag (a field called ignoreMe_)
> 2) Synchronize on an object that protects the linked list
> 3) Follow the chain of next pointers in the linked list and remove the first flagged object
> 4) Release synchronization lock obtained in (2)
> 5) Clear the flag set in (1)
> Now, say that two threads (T1 and T2) perform step 1 in parallel. T1 is granted the synchronization lock in (2), and T2 must wait. T1 traverses the linked list, finds the object flagged by T2 and removes it. Further T1 releases the synchronization lock and clears the flag on the object it had flagged. This is not the same object that it removed, so when T2 is granted the synchronization lock, there is no object flagged for removal. As a result, only the object T2 attempted to remove was in fact removed. The object that T1 flagged for removal is still in the linked list.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Closed: (DERBY-3909) Race condition in
NetXAResource.removeXaresFromSameRMchain()
Posted by "Knut Anders Hatlen (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/DERBY-3909?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Knut Anders Hatlen closed DERBY-3909.
-------------------------------------
> Race condition in NetXAResource.removeXaresFromSameRMchain()
> ------------------------------------------------------------
>
> Key: DERBY-3909
> URL: https://issues.apache.org/jira/browse/DERBY-3909
> Project: Derby
> Issue Type: Bug
> Components: Network Client
> Affects Versions: 10.2.2.0, 10.5.0.0
> Reporter: Knut Anders Hatlen
> Assignee: Knut Anders Hatlen
> Fix For: 10.2.2.1, 10.3.3.1, 10.4.2.1, 10.5.0.0
>
> Attachments: d3909-remove.diff, d3909.diff, Derby3909.java
>
>
> NetXAResource.removeXaresFromSameRMchain() does the following to remove a NetXAResource from what's logically a singly-linked list:
> 1) Mark the NetXAResource to remove with a flag (a field called ignoreMe_)
> 2) Synchronize on an object that protects the linked list
> 3) Follow the chain of next pointers in the linked list and remove the first flagged object
> 4) Release synchronization lock obtained in (2)
> 5) Clear the flag set in (1)
> Now, say that two threads (T1 and T2) perform step 1 in parallel. T1 is granted the synchronization lock in (2), and T2 must wait. T1 traverses the linked list, finds the object flagged by T2 and removes it. Further T1 releases the synchronization lock and clears the flag on the object it had flagged. This is not the same object that it removed, so when T2 is granted the synchronization lock, there is no object flagged for removal. As a result, only the object T2 attempted to remove was in fact removed. The object that T1 flagged for removal is still in the linked list.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Updated: (DERBY-3909) Race condition in
NetXAResource.removeXaresFromSameRMchain()
Posted by "Knut Anders Hatlen (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/DERBY-3909?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Knut Anders Hatlen updated DERBY-3909:
--------------------------------------
Affects Version/s: 10.2.2.0
A SailFin user reported this problem against Derby 10.2. See https://sailfin.dev.java.net/issues/show_bug.cgi?id=1218. He also said that the problem went away if he used 10.4.2.0 instead.
I see something similar with the repro I attached here. On 10.2 and 10.3, the repro ends up in an infinite loop in initForReuse() after 10-20 seconds. On 10.4 and trunk, the repro just slows down.
A binary search in the repository revealed that the behaviour changed with this check-in:
------------------------------------------------------------------------
r632334 | kristwaa | 2008-02-29 15:59:32 +0100 (fr, 29 feb 2008) | 3 lines
DERBY-3441: Determine and implement a proper procedure for resetting a prepared statement for reuse in a statement pool.
Patch file: derby-3441-1c-statement_reset.diff
------------------------------------------------------------------------
This check-in appears to change the timing of establishing and reusing XA connections, most likely because of the changes to client.am.Connection.completeReset() which seem to change how the transaction isolation level is reset. There's also a TODO comment which says we should investigate other ways to do it.
Although I don't see the infinite loop after that commit, the potential for the infinite loop is still there, and I still see that the vector keeps growing.
> Race condition in NetXAResource.removeXaresFromSameRMchain()
> ------------------------------------------------------------
>
> Key: DERBY-3909
> URL: https://issues.apache.org/jira/browse/DERBY-3909
> Project: Derby
> Issue Type: Bug
> Components: Network Client
> Affects Versions: 10.2.2.0, 10.5.0.0
> Reporter: Knut Anders Hatlen
> Assignee: Knut Anders Hatlen
> Attachments: d3909-remove.diff, d3909.diff, Derby3909.java
>
>
> NetXAResource.removeXaresFromSameRMchain() does the following to remove a NetXAResource from what's logically a singly-linked list:
> 1) Mark the NetXAResource to remove with a flag (a field called ignoreMe_)
> 2) Synchronize on an object that protects the linked list
> 3) Follow the chain of next pointers in the linked list and remove the first flagged object
> 4) Release synchronization lock obtained in (2)
> 5) Clear the flag set in (1)
> Now, say that two threads (T1 and T2) perform step 1 in parallel. T1 is granted the synchronization lock in (2), and T2 must wait. T1 traverses the linked list, finds the object flagged by T2 and removes it. Further T1 releases the synchronization lock and clears the flag on the object it had flagged. This is not the same object that it removed, so when T2 is granted the synchronization lock, there is no object flagged for removal. As a result, only the object T2 attempted to remove was in fact removed. The object that T1 flagged for removal is still in the linked list.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Updated: (DERBY-3909) Race condition in
NetXAResource.removeXaresFromSameRMchain()
Posted by "Knut Anders Hatlen (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/DERBY-3909?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Knut Anders Hatlen updated DERBY-3909:
--------------------------------------
Attachment: Derby3909.java
Attaching the test I described in my previous comment.
> Race condition in NetXAResource.removeXaresFromSameRMchain()
> ------------------------------------------------------------
>
> Key: DERBY-3909
> URL: https://issues.apache.org/jira/browse/DERBY-3909
> Project: Derby
> Issue Type: Bug
> Components: Network Client
> Affects Versions: 10.5.0.0
> Reporter: Knut Anders Hatlen
> Assignee: Knut Anders Hatlen
> Attachments: d3909.diff, Derby3909.java
>
>
> NetXAResource.removeXaresFromSameRMchain() does the following to remove a NetXAResource from what's logically a singly-linked list:
> 1) Mark the NetXAResource to remove with a flag (a field called ignoreMe_)
> 2) Synchronize on an object that protects the linked list
> 3) Follow the chain of next pointers in the linked list and remove the first flagged object
> 4) Release synchronization lock obtained in (2)
> 5) Clear the flag set in (1)
> Now, say that two threads (T1 and T2) perform step 1 in parallel. T1 is granted the synchronization lock in (2), and T2 must wait. T1 traverses the linked list, finds the object flagged by T2 and removes it. Further T1 releases the synchronization lock and clears the flag on the object it had flagged. This is not the same object that it removed, so when T2 is granted the synchronization lock, there is no object flagged for removal. As a result, only the object T2 attempted to remove was in fact removed. The object that T1 flagged for removal is still in the linked list.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Updated: (DERBY-3909) Race condition in
NetXAResource.removeXaresFromSameRMchain()
Posted by "Knut Anders Hatlen (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/DERBY-3909?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Knut Anders Hatlen updated DERBY-3909:
--------------------------------------
Derby Info: [Patch Available]
> Race condition in NetXAResource.removeXaresFromSameRMchain()
> ------------------------------------------------------------
>
> Key: DERBY-3909
> URL: https://issues.apache.org/jira/browse/DERBY-3909
> Project: Derby
> Issue Type: Bug
> Components: Network Client
> Affects Versions: 10.5.0.0
> Reporter: Knut Anders Hatlen
> Assignee: Knut Anders Hatlen
> Attachments: d3909.diff
>
>
> NetXAResource.removeXaresFromSameRMchain() does the following to remove a NetXAResource from what's logically a singly-linked list:
> 1) Mark the NetXAResource to remove with a flag (a field called ignoreMe_)
> 2) Synchronize on an object that protects the linked list
> 3) Follow the chain of next pointers in the linked list and remove the first flagged object
> 4) Release synchronization lock obtained in (2)
> 5) Clear the flag set in (1)
> Now, say that two threads (T1 and T2) perform step 1 in parallel. T1 is granted the synchronization lock in (2), and T2 must wait. T1 traverses the linked list, finds the object flagged by T2 and removes it. Further T1 releases the synchronization lock and clears the flag on the object it had flagged. This is not the same object that it removed, so when T2 is granted the synchronization lock, there is no object flagged for removal. As a result, only the object T2 attempted to remove was in fact removed. The object that T1 flagged for removal is still in the linked list.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (DERBY-3909) Race condition in
NetXAResource.removeXaresFromSameRMchain()
Posted by "Knut Anders Hatlen (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/DERBY-3909?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12638851#action_12638851 ]
Knut Anders Hatlen commented on DERBY-3909:
-------------------------------------------
There are more problems with the handling of this data structure.
I wrote a test which had 10 threads that opened and closed XA
connections in parallel, and every 5 seconds it would print how many
operations it had performed. The test showed that the number of
operations per interval decreased over time, and when I instrumented
the code I found that the vector xaResourceSameRMGroup_ in
NetXAResource just kept growing. xaResourceSameRMGroup_ holds the
singly-linked lists that this issue was originally opened for.
Since the vector is meant to have one item per resource manager
(which, as I understand it, is a Derby network server in this
context), and all the threads connect to the same server, the vector
should never have more than one element in this test.
The problem is this:
NetXAResource.initForReuse() scans through the vector to find the
correct group to add the XAResource to. The correct group is one for
which isSameRM() returns true. XAResources that belong to the same
group are chained.
But if the first XAResource in one of the chains belongs to a closed
connection whose XAResource has not yet been removed from the chain
(yet another race condition), an XAException is raised, and
initForReuse() notices it and just continues the search on the next
element in the vector. If the group that was skipped because of the
XAException, was the group that the XAResource actually should have
been added to, the search won't find a matching group, and a new
element will be added to the vector. So we end up with multiple chains
for a single group.
Also, since the XAResource may even exist from before in the skipped
group, it will end up two places in the vector. When the XAConnection
is closed later on, only one of the occurrences of the XAResource will
be removed from the vector, which means that the vector could become
very large over time.
Even worse, the next pointers used to chain NetXAResource objects that
belong to the same group, are not cleared when the object is removed
from the chain or when the NetXAResource is added as the root of a new
group. If it is already part of a group that was skipped because of an
XAException, it could have a next pointer which points to another
chain, and with some bad luck we could end up with a cycle in one of
the chains and make initForReuse() and removeXaresFromSameRMchain()
vulnerable to infinite loops.
It looks like the problem could be solved simply by turning around the
call to NetXAResource.isSameRM() in initForReuse(), from
xaResourceGroup.isSameRM(this) to isSameRM(xaResourceGroup). Since the
connection used by "this" is not closed, the XAException is not
thrown, and the NetXAResource is added to the correct group.
However, I can't see that this data structure is used anywhere in the
code. The fields that build up the structure are only used in
initForReuse() and removeXaresFromSameRMchain(), so we only put things
in and remove them, without doing anything useful with them in
between. Given that the code that handles the data structure has a
number of problems, is fairly complex and doesn't seem to do anything
useful, I would suggest that we remove it instead of trying to fix it.
> Race condition in NetXAResource.removeXaresFromSameRMchain()
> ------------------------------------------------------------
>
> Key: DERBY-3909
> URL: https://issues.apache.org/jira/browse/DERBY-3909
> Project: Derby
> Issue Type: Bug
> Components: Network Client
> Affects Versions: 10.5.0.0
> Reporter: Knut Anders Hatlen
> Assignee: Knut Anders Hatlen
> Attachments: d3909.diff
>
>
> NetXAResource.removeXaresFromSameRMchain() does the following to remove a NetXAResource from what's logically a singly-linked list:
> 1) Mark the NetXAResource to remove with a flag (a field called ignoreMe_)
> 2) Synchronize on an object that protects the linked list
> 3) Follow the chain of next pointers in the linked list and remove the first flagged object
> 4) Release synchronization lock obtained in (2)
> 5) Clear the flag set in (1)
> Now, say that two threads (T1 and T2) perform step 1 in parallel. T1 is granted the synchronization lock in (2), and T2 must wait. T1 traverses the linked list, finds the object flagged by T2 and removes it. Further T1 releases the synchronization lock and clears the flag on the object it had flagged. This is not the same object that it removed, so when T2 is granted the synchronization lock, there is no object flagged for removal. As a result, only the object T2 attempted to remove was in fact removed. The object that T1 flagged for removal is still in the linked list.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Updated: (DERBY-3909) Race condition in
NetXAResource.removeXaresFromSameRMchain()
Posted by "Knut Anders Hatlen (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/DERBY-3909?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Knut Anders Hatlen updated DERBY-3909:
--------------------------------------
Derby Info: (was: [Patch Available])
Fix Version/s: 10.5.0.0
Committed d3909-remove.diff to trunk with revision 704904.
I'm planning to back-port the fix to all branches back to 10.2 since users have seen this problem on 10.2.
> Race condition in NetXAResource.removeXaresFromSameRMchain()
> ------------------------------------------------------------
>
> Key: DERBY-3909
> URL: https://issues.apache.org/jira/browse/DERBY-3909
> Project: Derby
> Issue Type: Bug
> Components: Network Client
> Affects Versions: 10.2.2.0, 10.5.0.0
> Reporter: Knut Anders Hatlen
> Assignee: Knut Anders Hatlen
> Fix For: 10.5.0.0
>
> Attachments: d3909-remove.diff, d3909.diff, Derby3909.java
>
>
> NetXAResource.removeXaresFromSameRMchain() does the following to remove a NetXAResource from what's logically a singly-linked list:
> 1) Mark the NetXAResource to remove with a flag (a field called ignoreMe_)
> 2) Synchronize on an object that protects the linked list
> 3) Follow the chain of next pointers in the linked list and remove the first flagged object
> 4) Release synchronization lock obtained in (2)
> 5) Clear the flag set in (1)
> Now, say that two threads (T1 and T2) perform step 1 in parallel. T1 is granted the synchronization lock in (2), and T2 must wait. T1 traverses the linked list, finds the object flagged by T2 and removes it. Further T1 releases the synchronization lock and clears the flag on the object it had flagged. This is not the same object that it removed, so when T2 is granted the synchronization lock, there is no object flagged for removal. As a result, only the object T2 attempted to remove was in fact removed. The object that T1 flagged for removal is still in the linked list.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Resolved: (DERBY-3909) Race condition in
NetXAResource.removeXaresFromSameRMchain()
Posted by "Knut Anders Hatlen (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/DERBY-3909?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Knut Anders Hatlen resolved DERBY-3909.
---------------------------------------
Resolution: Fixed
Fix Version/s: 10.4.2.1
10.3.3.1
10.2.2.1
Committed to 10.4 with revision 705218.
Committed to 10.3 with revision 705219.
Committed to 10.2 with revision 705220.
Marking the issue as resolved since the problematic code has been removed.
> Race condition in NetXAResource.removeXaresFromSameRMchain()
> ------------------------------------------------------------
>
> Key: DERBY-3909
> URL: https://issues.apache.org/jira/browse/DERBY-3909
> Project: Derby
> Issue Type: Bug
> Components: Network Client
> Affects Versions: 10.2.2.0, 10.5.0.0
> Reporter: Knut Anders Hatlen
> Assignee: Knut Anders Hatlen
> Fix For: 10.2.2.1, 10.3.3.1, 10.4.2.1, 10.5.0.0
>
> Attachments: d3909-remove.diff, d3909.diff, Derby3909.java
>
>
> NetXAResource.removeXaresFromSameRMchain() does the following to remove a NetXAResource from what's logically a singly-linked list:
> 1) Mark the NetXAResource to remove with a flag (a field called ignoreMe_)
> 2) Synchronize on an object that protects the linked list
> 3) Follow the chain of next pointers in the linked list and remove the first flagged object
> 4) Release synchronization lock obtained in (2)
> 5) Clear the flag set in (1)
> Now, say that two threads (T1 and T2) perform step 1 in parallel. T1 is granted the synchronization lock in (2), and T2 must wait. T1 traverses the linked list, finds the object flagged by T2 and removes it. Further T1 releases the synchronization lock and clears the flag on the object it had flagged. This is not the same object that it removed, so when T2 is granted the synchronization lock, there is no object flagged for removal. As a result, only the object T2 attempted to remove was in fact removed. The object that T1 flagged for removal is still in the linked list.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (DERBY-3909) Race condition in
NetXAResource.removeXaresFromSameRMchain()
Posted by "Knut Anders Hatlen (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/DERBY-3909?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12638774#action_12638774 ]
Knut Anders Hatlen commented on DERBY-3909:
-------------------------------------------
The problem could be solved by obtaining the synchronization lock earlier and releasing it later, or by checking for object identity instead of the ignoreMe_ flag when removing an object. I would prefer checking the object identity, as I think the code will be clearer that way. We could then also remove the ignoreMe_ field from the class.
> Race condition in NetXAResource.removeXaresFromSameRMchain()
> ------------------------------------------------------------
>
> Key: DERBY-3909
> URL: https://issues.apache.org/jira/browse/DERBY-3909
> Project: Derby
> Issue Type: Bug
> Components: Network Client
> Affects Versions: 10.5.0.0
> Reporter: Knut Anders Hatlen
> Assignee: Knut Anders Hatlen
>
> NetXAResource.removeXaresFromSameRMchain() does the following to remove a NetXAResource from what's logically a singly-linked list:
> 1) Mark the NetXAResource to remove with a flag (a field called ignoreMe_)
> 2) Synchronize on an object that protects the linked list
> 3) Follow the chain of next pointers in the linked list and remove the first flagged object
> 4) Release synchronization lock obtained in (2)
> 5) Clear the flag set in (1)
> Now, say that two threads (T1 and T2) perform step 1 in parallel. T1 is granted the synchronization lock in (2), and T2 must wait. T1 traverses the linked list, finds the object flagged by T2 and removes it. Further T1 releases the synchronization lock and clears the flag on the object it had flagged. This is not the same object that it removed, so when T2 is granted the synchronization lock, there is no object flagged for removal. As a result, only the object T2 attempted to remove was in fact removed. The object that T1 flagged for removal is still in the linked list.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Updated: (DERBY-3909) Race condition in
NetXAResource.removeXaresFromSameRMchain()
Posted by "Knut Anders Hatlen (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/DERBY-3909?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Knut Anders Hatlen updated DERBY-3909:
--------------------------------------
Attachment: d3909.diff
Here's a patch that attempts to fix the problem by checking the identity instead of the field ignoreMe_. I haven't found any way to test it, since I don't have a test case that exposes the problem, but I believe that the patch is an improvement. Derbyall and suites.All ran cleanly with the patch. Reviews would be appreciated.
> Race condition in NetXAResource.removeXaresFromSameRMchain()
> ------------------------------------------------------------
>
> Key: DERBY-3909
> URL: https://issues.apache.org/jira/browse/DERBY-3909
> Project: Derby
> Issue Type: Bug
> Components: Network Client
> Affects Versions: 10.5.0.0
> Reporter: Knut Anders Hatlen
> Assignee: Knut Anders Hatlen
> Attachments: d3909.diff
>
>
> NetXAResource.removeXaresFromSameRMchain() does the following to remove a NetXAResource from what's logically a singly-linked list:
> 1) Mark the NetXAResource to remove with a flag (a field called ignoreMe_)
> 2) Synchronize on an object that protects the linked list
> 3) Follow the chain of next pointers in the linked list and remove the first flagged object
> 4) Release synchronization lock obtained in (2)
> 5) Clear the flag set in (1)
> Now, say that two threads (T1 and T2) perform step 1 in parallel. T1 is granted the synchronization lock in (2), and T2 must wait. T1 traverses the linked list, finds the object flagged by T2 and removes it. Further T1 releases the synchronization lock and clears the flag on the object it had flagged. This is not the same object that it removed, so when T2 is granted the synchronization lock, there is no object flagged for removal. As a result, only the object T2 attempted to remove was in fact removed. The object that T1 flagged for removal is still in the linked list.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Updated: (DERBY-3909) Race condition in
NetXAResource.removeXaresFromSameRMchain()
Posted by "Knut Anders Hatlen (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/DERBY-3909?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Knut Anders Hatlen updated DERBY-3909:
--------------------------------------
Derby Info: [Patch Available]
> Race condition in NetXAResource.removeXaresFromSameRMchain()
> ------------------------------------------------------------
>
> Key: DERBY-3909
> URL: https://issues.apache.org/jira/browse/DERBY-3909
> Project: Derby
> Issue Type: Bug
> Components: Network Client
> Affects Versions: 10.5.0.0
> Reporter: Knut Anders Hatlen
> Assignee: Knut Anders Hatlen
> Attachments: d3909-remove.diff, d3909.diff, Derby3909.java
>
>
> NetXAResource.removeXaresFromSameRMchain() does the following to remove a NetXAResource from what's logically a singly-linked list:
> 1) Mark the NetXAResource to remove with a flag (a field called ignoreMe_)
> 2) Synchronize on an object that protects the linked list
> 3) Follow the chain of next pointers in the linked list and remove the first flagged object
> 4) Release synchronization lock obtained in (2)
> 5) Clear the flag set in (1)
> Now, say that two threads (T1 and T2) perform step 1 in parallel. T1 is granted the synchronization lock in (2), and T2 must wait. T1 traverses the linked list, finds the object flagged by T2 and removes it. Further T1 releases the synchronization lock and clears the flag on the object it had flagged. This is not the same object that it removed, so when T2 is granted the synchronization lock, there is no object flagged for removal. As a result, only the object T2 attempted to remove was in fact removed. The object that T1 flagged for removal is still in the linked list.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.