@@ -628,7 +628,9 @@ public void run() {
628
628
} catch (Exception exp ) {
629
629
processException (exp );
630
630
try {
631
- this .closeSocket (false );
631
+ // allow force reconnect since this is pretty exceptional,
632
+ // a connection failure while trying to connect
633
+ this .closeSocket (false , true );
632
634
} catch (InterruptedException e ) {
633
635
processException (e );
634
636
}
@@ -691,7 +693,9 @@ void handleCommunicationIssue(Exception io) {
691
693
// waiting on read/write threads
692
694
executor .submit (() -> {
693
695
try {
694
- this .closeSocket (true );
696
+ // any issue that brings us here is pretty serious
697
+ // so we are comfortable forcing the close
698
+ this .closeSocket (true , true );
695
699
} catch (InterruptedException e ) {
696
700
processException (e );
697
701
Thread .currentThread ().interrupt ();
@@ -701,7 +705,7 @@ void handleCommunicationIssue(Exception io) {
701
705
702
706
// Close socket is called when another connect attempt is possible
703
707
// Close is called when the connection should shut down, period
704
- void closeSocket (boolean tryReconnectIfConnected ) throws InterruptedException {
708
+ void closeSocket (boolean tryReconnectIfConnected , boolean forceClose ) throws InterruptedException {
705
709
// Ensure we close the socket exclusively within one thread.
706
710
closeSocketLock .lock ();
707
711
try {
@@ -720,7 +724,7 @@ void closeSocket(boolean tryReconnectIfConnected) throws InterruptedException {
720
724
statusLock .unlock ();
721
725
}
722
726
723
- closeSocketImpl ();
727
+ closeSocketImpl (forceClose );
724
728
725
729
statusLock .lock ();
726
730
try {
@@ -749,10 +753,10 @@ void closeSocket(boolean tryReconnectIfConnected) throws InterruptedException {
749
753
*/
750
754
@ Override
751
755
public void close () throws InterruptedException {
752
- this .close (true );
756
+ this .close (true , false );
753
757
}
754
758
755
- void close (boolean checkDrainStatus ) throws InterruptedException {
759
+ void close (boolean checkDrainStatus , boolean forceClose ) throws InterruptedException {
756
760
statusLock .lock ();
757
761
try {
758
762
if (checkDrainStatus && this .isDraining ()) {
@@ -779,7 +783,7 @@ void close(boolean checkDrainStatus) throws InterruptedException {
779
783
this .reconnectWaiter .cancel (true );
780
784
}
781
785
782
- closeSocketImpl ();
786
+ closeSocketImpl (forceClose );
783
787
784
788
this .dispatchers .forEach ((nuid , d ) -> d .stop (false ));
785
789
@@ -831,7 +835,7 @@ void close(boolean checkDrainStatus) throws InterruptedException {
831
835
}
832
836
833
837
// Should only be called from closeSocket or close
834
- void closeSocketImpl () {
838
+ void closeSocketImpl (boolean forceClose ) {
835
839
this .currentServer = null ;
836
840
837
841
// Signal both to stop.
@@ -854,8 +858,13 @@ void closeSocketImpl() {
854
858
855
859
// Close the current socket and cancel anyone waiting for it
856
860
try {
857
- if (this .dataPort != null ) {
858
- this .dataPort .close ();
861
+ if (dataPort != null ) {
862
+ if (forceClose ) {
863
+ dataPort .forceClose ();
864
+ }
865
+ else {
866
+ dataPort .close ();
867
+ }
859
868
}
860
869
861
870
} catch (IOException ex ) {
@@ -2121,7 +2130,7 @@ public CompletableFuture<Boolean> drain(Duration timeout) throws TimeoutExceptio
2121
2130
try {
2122
2131
this .flush (timeout ); // Flush and wait up to the timeout, if this fails, let the caller know
2123
2132
} catch (Exception e ) {
2124
- this .close (false );
2133
+ this .close (false , false );
2125
2134
throw e ;
2126
2135
}
2127
2136
@@ -2163,13 +2172,13 @@ public CompletableFuture<Boolean> drain(Duration timeout) throws TimeoutExceptio
2163
2172
}
2164
2173
}
2165
2174
2166
- this .close (false ); // close the connection after the last flush
2175
+ this .close (false , false ); // close the connection after the last flush
2167
2176
tracker .complete (consumers .isEmpty ());
2168
2177
} catch (TimeoutException | InterruptedException e ) {
2169
2178
this .processException (e );
2170
2179
} finally {
2171
2180
try {
2172
- this .close (false );// close the connection after the last flush
2181
+ this .close (false , false );// close the connection after the last flush
2173
2182
} catch (InterruptedException e ) {
2174
2183
processException (e );
2175
2184
Thread .currentThread ().interrupt ();
0 commit comments