You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@directory.apache.org by "Emmanuel Lécharny (Jira)" <ji...@apache.org> on 2025/04/17 21:42:00 UTC
[jira] [Commented] (DIRSERVER-2418) Potential Synchronization Issue At AbstractBTreePartition
[ https://issues.apache.org/jira/browse/DIRSERVER-2418?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17945519#comment-17945519 ]
Emmanuel Lécharny commented on DIRSERVER-2418:
----------------------------------------------
Hi,
this is a real issue. I think this change would fix it:
{code:java}
public String getSuffixId( PartitionTxn partitionTxn ) throws LdapException
{
if ( suffixId == null )
{
ParentIdAndRdn key = new ParentIdAndRdn( Partition.ROOT_ID, suffixDn.getRdns() );
try
{
rwLock.readLock().lock();
if ( suffixId == null )
{
suffixId = rdnIdx.forwardLookup( partitionTxn, key );
}
}
finally
{
rwLock.readLock().unlock();
}
}
return suffixId;
{code}
Note that the {{suffixId}} variable is declared {{volatile}} which guarantees hat there can't be a partial initialization.
> Potential Synchronization Issue At AbstractBTreePartition
> ----------------------------------------------------------
>
> Key: DIRSERVER-2418
> URL: https://issues.apache.org/jira/browse/DIRSERVER-2418
> Project: Directory ApacheDS
> Issue Type: Bug
> Reporter: Mikhail Titov
> Priority: Major
>
> Let's take a look at the [getSuffixId|https://github.com/apache/directory-server/blob/38e7e2bdb685f71c8f7726197bfbd22cce33ba3a/xdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/AbstractBTreePartition.java#L2995] method:
> Field *suffixId* has been compared without locking at [link|https://github.com/apache/directory-server/blob/38e7e2bdb685f71c8f7726197bfbd22cce33ba3a/xdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/AbstractBTreePartition.java#L2997] and is assigned under lock at [link|https://github.com/apache/directory-server/blob/38e7e2bdb685f71c8f7726197bfbd22cce33ba3a/xdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/AbstractBTreePartition.java#L3004].
> This potentially may lead to a synchronization error, when many processes simultaneously pass the check and then reach the lock one by one.
> The problem and possible resolve are described in more detail [here|https://stackoverflow.com/questions/13261300/is-it-okay-to-double-check-before-and-inside-a-lock-before-running-the-code-in#:~:text=The%20first%20method,a%20performance%20issue.]
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@directory.apache.org
For additional commands, e-mail: dev-help@directory.apache.org