55
55
import reactor .core .publisher .Operators ;
56
56
import reactor .core .scheduler .Schedulers ;
57
57
import reactor .netty .Connection ;
58
+ import reactor .netty .channel .AbortedException ;
58
59
import reactor .netty .resources .ConnectionProvider ;
59
60
import reactor .netty .resources .LoopResources ;
60
61
import reactor .netty .tcp .TcpClient ;
@@ -513,6 +514,11 @@ private void handleClose() {
513
514
}
514
515
515
516
private void handleConnectionError (Throwable error ) {
517
+
518
+ if (AbortedException .isConnectionReset (error ) && !isConnected ()) {
519
+ drainError (() -> this .messageSubscriber .createClientClosedException (error ));
520
+ }
521
+
516
522
drainError (() -> new PostgresConnectionException (error ));
517
523
}
518
524
@@ -554,6 +560,10 @@ public PostgresConnectionClosedException(String reason) {
554
560
super (reason );
555
561
}
556
562
563
+ public PostgresConnectionClosedException (String reason , @ Nullable Throwable cause ) {
564
+ super (reason , cause );
565
+ }
566
+
557
567
}
558
568
559
569
static class PostgresConnectionException extends R2dbcNonTransientResourceException {
@@ -689,7 +699,7 @@ private class BackendMessageSubscriber implements CoreSubscriber<BackendMessage>
689
699
690
700
private Subscription upstream ;
691
701
692
- public Flux <BackendMessage > addConversation (Predicate <BackendMessage > takeUntil , Publisher <FrontendMessage > requests , Consumer <Flux <FrontendMessage >> sender ,
702
+ public Flux <BackendMessage > addConversation (Predicate <BackendMessage > takeUntil , Publisher <FrontendMessage > requests , Consumer <Publisher <FrontendMessage >> sender ,
693
703
Supplier <Boolean > isConnected ) {
694
704
695
705
return Flux .create (sink -> {
@@ -707,13 +717,7 @@ public Flux<BackendMessage> addConversation(Predicate<BackendMessage> takeUntil,
707
717
return ;
708
718
}
709
719
710
- Flux <FrontendMessage > requestMessages = Flux .from (requests ).doOnNext (m -> {
711
- if (!isConnected .get ()) {
712
- sink .error (new PostgresConnectionClosedException ("Cannot exchange messages because the connection is closed" ));
713
- }
714
- });
715
-
716
- sender .accept (requestMessages );
720
+ sender .accept (requests );
717
721
} else {
718
722
sink .error (new RequestQueueException ("Cannot exchange messages because the request queue limit is exceeded" ));
719
723
}
@@ -722,7 +726,11 @@ public Flux<BackendMessage> addConversation(Predicate<BackendMessage> takeUntil,
722
726
}
723
727
724
728
PostgresConnectionClosedException createClientClosedException () {
725
- return new PostgresConnectionClosedException ("Cannot exchange messages because the connection is closed" );
729
+ return createClientClosedException (null );
730
+ }
731
+
732
+ PostgresConnectionClosedException createClientClosedException (@ Nullable Throwable cause ) {
733
+ return new PostgresConnectionClosedException ("Cannot exchange messages because the connection is closed" , cause );
726
734
}
727
735
728
736
/**
0 commit comments