File tree 2 files changed +31
-1
lines changed
main/java/io/grpc/internal
test/java/io/grpc/internal
2 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -561,7 +561,11 @@ public Attributes getAttributes() {
561
561
}
562
562
563
563
private void closeObserver (Listener <RespT > observer , Status status , Metadata trailers ) {
564
- observer .onClose (status , trailers );
564
+ try {
565
+ observer .onClose (status , trailers );
566
+ } catch (RuntimeException ex ) {
567
+ log .log (Level .WARNING , "Exception thrown by onClose() in ClientCall" , ex );
568
+ }
565
569
}
566
570
567
571
@ Override
Original file line number Diff line number Diff line change @@ -1105,6 +1105,32 @@ public void getAttributes() {
1105
1105
assertEquals (attrs , call .getAttributes ());
1106
1106
}
1107
1107
1108
+ @ Test
1109
+ public void onCloseExceptionCaughtAndLogged () {
1110
+ DelayedExecutor executor = new DelayedExecutor ();
1111
+ ClientCallImpl <Void , Void > call = new ClientCallImpl <>(
1112
+ method ,
1113
+ executor ,
1114
+ baseCallOptions ,
1115
+ clientStreamProvider ,
1116
+ deadlineCancellationExecutor ,
1117
+ channelCallTracer , configSelector );
1118
+
1119
+ call .start (callListener , new Metadata ());
1120
+ verify (stream ).start (listenerArgumentCaptor .capture ());
1121
+ final ClientStreamListener streamListener = listenerArgumentCaptor .getValue ();
1122
+ streamListener .headersRead (new Metadata ());
1123
+
1124
+ doThrow (new RuntimeException ("Exception thrown by onClose() in ClientCall" )).when (callListener )
1125
+ .onClose (any (Status .class ), any (Metadata .class ));
1126
+
1127
+ Status status = Status .RESOURCE_EXHAUSTED .withDescription ("simulated" );
1128
+ streamListener .closed (status , PROCESSED , new Metadata ());
1129
+ executor .release ();
1130
+
1131
+ verify (callListener ).onClose (same (status ), any (Metadata .class ));
1132
+ }
1133
+
1108
1134
private static final class DelayedExecutor implements Executor {
1109
1135
private final BlockingQueue <Runnable > commands = new LinkedBlockingQueue <>();
1110
1136
You can’t perform that action at this time.
0 commit comments