File tree Expand file tree Collapse file tree 2 files changed +31
-1
lines changed
main/java/io/grpc/internal
test/java/io/grpc/internal Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -561,7 +561,11 @@ public Attributes getAttributes() {
561561 }
562562
563563 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+ }
565569 }
566570
567571 @ Override
Original file line number Diff line number Diff line change @@ -1105,6 +1105,32 @@ public void getAttributes() {
11051105 assertEquals (attrs , call .getAttributes ());
11061106 }
11071107
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+
11081134 private static final class DelayedExecutor implements Executor {
11091135 private final BlockingQueue <Runnable > commands = new LinkedBlockingQueue <>();
11101136
You can’t perform that action at this time.
0 commit comments