Skip to content

Commit c9c890f

Browse files
author
Zhen Li
committed
Invalid current tx when session.reset is called to avoid running more tx in the reseted tx.
1 parent 7c91ca2 commit c9c890f

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

driver/src/main/java/org/neo4j/driver/internal/NetworkSession.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ public void reset()
109109
ensureNoUnrecoverableError();
110110
ensureConnectionIsOpen();
111111

112+
if( currentTransaction != null )
113+
{
114+
currentTransaction.markToClose();
115+
}
112116
connection.resetAsync();
113117
}
114118

driver/src/test/java/org/neo4j/driver/v1/integration/SessionIT.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.neo4j.driver.v1.util.TestNeo4j;
2828

2929
import static org.hamcrest.CoreMatchers.equalTo;
30+
import static org.hamcrest.CoreMatchers.startsWith;
3031
import static org.hamcrest.Matchers.greaterThan;
3132
import static org.junit.Assert.assertFalse;
3233
import static org.junit.Assert.assertThat;
@@ -238,4 +239,26 @@ public void shouldAllowMoreTxAfterSessionReset()
238239
}
239240
}
240241
}
242+
243+
@Test
244+
public void shouldMarkTxAsFailedAndDisAllowRunAfterSessionReset()
245+
{
246+
// Given
247+
try( Driver driver = GraphDatabase.driver( neo4j.uri() );
248+
Session session = driver.session() )
249+
{
250+
try( Transaction tx = session.beginTransaction() )
251+
{
252+
// When reset the state of this session
253+
session.reset();
254+
// Then
255+
tx.run( "Return 1" );
256+
fail( "Should not allow tx run as tx is already failed." );
257+
}
258+
catch( Exception e )
259+
{
260+
assertThat( e.getMessage(), startsWith( "Cannot run more statements in this transaction" ) );
261+
}
262+
}
263+
}
241264
}

0 commit comments

Comments
 (0)