Skip to content

Commit b0293bd

Browse files
committed
Improve tx marking
1 parent ac17aa5 commit b0293bd

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

driver/src/main/java/org/neo4j/driver/internal/async/UnmanagedTransaction.java

+24-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*/
1919
package org.neo4j.driver.internal.async;
2020

21+
import java.util.Arrays;
2122
import java.util.EnumSet;
2223
import java.util.concurrent.CompletionException;
2324
import java.util.concurrent.CompletionStage;
@@ -229,7 +230,29 @@ public boolean isOpen()
229230

230231
public void markTerminated( Throwable cause )
231232
{
232-
state = StateHolder.terminatedWith( cause );
233+
if ( state.value == State.TERMINATED )
234+
{
235+
if ( state.causeOfTermination != null )
236+
{
237+
addSuppressedWhenNotCaptured( state.causeOfTermination, cause );
238+
}
239+
}
240+
else
241+
{
242+
state = StateHolder.terminatedWith( cause );
243+
}
244+
}
245+
246+
private void addSuppressedWhenNotCaptured( Throwable currentCause, Throwable newCause )
247+
{
248+
if ( currentCause != newCause )
249+
{
250+
boolean noneMatch = Arrays.stream( currentCause.getSuppressed() ).noneMatch( suppressed -> suppressed == newCause );
251+
if ( noneMatch )
252+
{
253+
currentCause.addSuppressed( newCause );
254+
}
255+
}
233256
}
234257

235258
public Connection connection()

driver/src/main/java/org/neo4j/driver/internal/handlers/TransactionPullResponseCompletionListener.java

+1-4
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@ public void afterFailure( Throwable error )
4545
// always mark transaction as terminated because every error is "acknowledged" with a RESET message
4646
// so database forgets about the transaction after the first error
4747
// such transaction should not attempt to commit and can be considered as rolled back
48-
if ( tx.isOpen() )
49-
{
50-
tx.markTerminated( error );
51-
}
48+
tx.markTerminated( error );
5249
}
5350
}

0 commit comments

Comments
 (0)