grpc / grpc/grpc-java

BlockingStub returns iterator that cannot be closed

Offen
#2,409 10 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
docs
Vorherrschende Sprache
Java
Sterne
12.1k
Forks
4k
Ø Merge
2 T. 17 Std.
Gemergte PRs (30 T.)
37

Beschreibung

I use a blocking sub for a method that returns a stream of messages. The return type of it is `Iterator`. It turns out I cannot make grpc client to end the request (e.g. because of client failure). There are a number of cases where an open connection may stuck in client because of that

The implementation uses
`io.grpc.stub.ClientCalls#blockingServerStreamingCall(io.grpc.Channel, io.grpc.MethodDescriptor, io.grpc.CallOptions, ReqT)`

call, which in turn uses `BlockingResponseStream`. There is no way to reach the `io.grpc.ClientCall#cancel` method form the Iterator. Could be nice to wrap an Iterator or make it implement an interface in the similar way as done with ServerStreamObserver/ClientStreamObserver
The other approach could be to implement `AutoCloseable` from Java with this iterator

There is also a comment on the Iterator implementation class
```
// TODO(ejona86): determine how to allow ClientCall.cancel() in case of application error.
```

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Start with io.grpc.stub.ClientCalls#blockingServerStreamingCall and the BlockingResponseStream implementation, then read the TODO about allowing ClientCall.cancel() on application error. Compare the proposed Iterator wrapper, interface, and AutoCloseable approaches; done means a blocking streaming result can expose request cancellation without breaking its existing Iterator behavior.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
java
Bereich
api
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.