Skip to content

Commit d898bc4

Browse files
committed
GH-2583 - Avoid possible deadlock.
1 parent 2561524 commit d898bc4

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/main/java/org/springframework/data/neo4j/core/mapping/DefaultNeo4jEntityConverter.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -872,22 +872,25 @@ private boolean alreadyMappedInPreviousRecord(@Nullable Long internalId) {
872872
}
873873
}
874874

875+
/**
876+
* This method has an intended side effect.
877+
* It increases the process count of relationships (mapped by their ids)
878+
* AND checks if it was already processed twice (INCOMING/OUTGOING).
879+
*/
875880
private boolean hasProcessedRelationshipCompletely(Long relationshipId) {
876881
try {
877882
write.lock();
878-
read.lock();
879883

880-
int amount = processedRelationships.computeIfAbsent(relationshipId, s -> 0);
881-
if (amount == 2) {
884+
int processedAmount = processedRelationships.computeIfAbsent(relationshipId, s -> 0);
885+
if (processedAmount == 2) {
882886
return true;
883887
}
884888

885-
processedRelationships.put(relationshipId, amount + 1);
889+
processedRelationships.put(relationshipId, processedAmount + 1);
886890
return false;
887891

888892
} finally {
889893
write.unlock();
890-
read.unlock();
891894
}
892895
}
893896

0 commit comments

Comments
 (0)