Skip to content

Commit 6da7f47

Browse files
committed
Prevent reporting previous error on session closure
1 parent 3eb3613 commit 6da7f47

File tree

3 files changed

+296
-281
lines changed

3 files changed

+296
-281
lines changed

driver/src/main/java/org/neo4j/driver/internal/cursor/RxResultCursorImpl.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.util.Objects;
2323
import java.util.concurrent.CompletableFuture;
2424
import java.util.concurrent.CompletionStage;
25+
import java.util.concurrent.atomic.AtomicReference;
2526
import java.util.function.BiConsumer;
2627

2728
import org.neo4j.driver.Record;
@@ -42,6 +43,7 @@ public class RxResultCursorImpl implements RxResultCursor
4243
private final PullResponseHandler pullHandler;
4344
private final Throwable runResponseError;
4445
private final CompletableFuture<ResultSummary> summaryFuture = new CompletableFuture<>();
46+
private final AtomicReference<Throwable> lastReportedError = new AtomicReference<>();
4547
private boolean resultConsumed;
4648
private RecordConsumerStatus consumerStatus = NOT_INSTALLED;
4749

@@ -81,6 +83,13 @@ public void installRecordConsumer( BiConsumer<Record,Throwable> recordConsumer )
8183
}
8284
consumerStatus = recordConsumer == DISCARD_RECORD_CONSUMER ?
8385
DISCARD_INSTALLED : INSTALLED;
86+
recordConsumer = recordConsumer.andThen( ( record, throwable ) ->
87+
{
88+
if ( throwable != null )
89+
{
90+
lastReportedError.set( throwable );
91+
}
92+
} );
8493
pullHandler.installRecordConsumer( recordConsumer );
8594
assertRunCompletedSuccessfully();
8695
}
@@ -105,7 +114,12 @@ public void cancel()
105114
public CompletionStage<Throwable> discardAllFailureAsync()
106115
{
107116
// calling this method will enforce discarding record stream and finish running cypher query
108-
return summaryAsync().thenApply( summary -> (Throwable) null ).exceptionally( error -> error );
117+
return summaryAsync().thenApply( summary -> (Throwable) null ).exceptionally(
118+
error ->
119+
{
120+
Throwable lastReported = lastReportedError.get();
121+
return lastReported != null && (lastReported == error || lastReported == error.getCause()) ? null : error;
122+
} );
109123
}
110124

111125
@Override
@@ -153,6 +167,7 @@ private void installSummaryConsumer()
153167
{
154168
// We will only report the error to summary if there is no user record consumer installed
155169
// When a user record consumer is installed, the error will be reported to record consumer instead.
170+
lastReportedError.set( error );
156171
summaryFuture.completeExceptionally( error );
157172
}
158173
else if ( summary != null )

0 commit comments

Comments
 (0)