On Fri, Apr 13, 2018 at 3:32 PM, Christopher Schechter <chrissc...@gmail.com
> wrote:

> Inside testService, it has this server-side streaming method:
>
> // for the purpose of this test, this queue is pre-filled with a handful
> of StreamItems, and never has any other objects added to it
> BlockingQueue<StreamItem> queue = new LinkedBlockingQueue<>();
>
>     @Override
>     public void testStream(StreamRequest request,
> StreamObserver<StreamItem> responseObserver) {
>         try {
>             while (!Thread.interrupted()) {
>                 StreamItem next = queue.poll();
>                 if (next == null) {
>                     LOGGER.debug("Queue is empty, waiting before next
> poll()");
>                     Thread.sleep(1000);
>                     // send default instance which is empty, to signal
> that the queue is empty right now
>                     responseObserver.onNext(StreamItem.getDefaultInstance(
> ));
>                 } else {
>                     responseObserver.onNext(next);
>                 }
>             }
>         } catch (InterruptedException e) {
>             LOGGER.info("Interrupted. Exiting loop.");
>         } catch (Exception e) {
>             LOGGER.error("Unexpected error", e);
>             responseObserver.onError(e);
>             return;
>         }
>         responseObserver.onCompleted();
>     }
>

Because this method doesn't return, it blocks the callback thread which
delivers notifications. We have checks to throw if the client cancelled,
but they aren't triggering. I just filed an issue for this
<https://github.com/grpc/grpc-java/issues/4351>.

For quick fix, you can cast responseObserver to ServerCallStreamObserver
and check isCancelled() as part of the loop. Alternatively, you can rely on
the gRPC Context by calling Context.current().isCancelled().

-- 
You received this message because you are subscribed to the Google Groups 
"grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to grpc-io+unsubscr...@googlegroups.com.
To post to this group, send email to grpc-io@googlegroups.com.
Visit this group at https://groups.google.com/group/grpc-io.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/grpc-io/CA%2B4M1oNdGNw2-_ON-jp08%2B2mU8YATqSmROd7Pt0LkvxoLasJYA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

Reply via email to