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:23:44 UTC

[jira] Commented: (DERBY-3909) Race condition in NetXAResource.removeXaresFromSameRMchain()

    [ 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.