Question about how to explicitly acquire a read lock for a transaction


I was wondering if I explicitly acquire a read lock then use the node, will the transaction drop the lock?

I tried running a test for this but for some reason when I tried to run more than 2 cypher queries in a transaction using neo4j sandbox, the transaction stalled on the third and didn't give me a reason.

Is the read lock on node (a: A) ever dropped during the transaction, after it is acquired in the explicit call?

def fn(tx):"MATCH (a: A) call[a]) RETURN NULL").consume()
    # POINT 1"MATCH (a: A) RETURN a.prop").consume()
   # POINT 3"call apoc.util.sleep(10000) RETURN NULL").consume()
   # POINT 4
   return TRUE

with driver.session() as session:

Hi @dansolnik I think maybe this could help you

Thank you! I have already read through that page. That's actually what helped me come up with the test case.

I was unable to run the test case on the sandbox and I do not have access to enterprise edition of neo4j.

Specifically, I run the following code on my computer:

from neo4j import GraphDatabase, basic_auth

def fn(tx):"MATCH (m: E) call[a]) RETURN NULL").consume()
    print("point 1")"MATCH (m: E) RETURN m.prop").consume()
    print("point 2")"call apoc.util.sleep(30000) RETURN NULL").consume()
    print("point 3")
    return True

def main():
    neo4j = GraphDatabase.driver(
        auth=basic_auth("neo4j", password))
    with neo4j.session() as session:


And then I try to use the techniques on that page to find the locks held by the process. However, it seems like the process just never runs the third part of the transaction and just gets stuck after point 2 with no active query.

hence, I was unable to answer my question.

ok, but now is it working?

I just gave it another try and it worked this time! There must have been something wrong with the sandbox I had.

The answer, for all those curious, is that the lock is held throughout the whole transaction. It is only released when the transaction is over.

1 Like

Thank you for your help!

no problem, if there is anything that I could help you let me know