-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BlockingStub returns iterator that cannot be closed #2409
Comments
I'm not wild about how the iterator has turned out either. Streaming+blocking in grpc-java is weak/missing. To do The main way to cancel would be to create and attach a |
I decided to use blocking API in tests, to simplify calls I only use in tests. It was not clear form the code. I was no javadoc hints for that. Will try |
Another option would be to have a method that returns a |
I'd like to add that not only an application error can prevent closing the iterator. I just tracked down a "direct buffer" ("LEAK: ByteBuf.release() was not called before...") memory leak in our system. It was caused by not iterating through all elements returned by the blocking stub's stub.getElements(request)
.asSequence()
.any { it.someProperty == 1234 } This is kotlin code and it looks very innocent. The However, because a sequence is evaluated lazily, as soon as |
@systemfreund There isn't anything we can really do about that. The suggestion to use |
@carl-mastrangelo Even |
@ejona86 I tried, but it doesn't seem to fix my problem. Is this expected to work? |
@pskiwi, no, that wouldn't work. After the cancellation you need to "drain" the Iterator; keep going until you get hasNext() == false. If you have a Draining the ThreadlessExecutor from a Context.CancellationListener scares me because of the threading involved. It would be possible to add a close() method to the Iterator (and require you to cast), but in general we're not wild about the blocking iterator API as it is far too hard to use properly. We think the proper fix here is to have a "real" blocking API. |
Does anyone have any examples for the use of |
I use a blocking sub for a method that returns a stream of messages. The return type of it is
Iterator<T>
. 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 thatThe implementation uses
io.grpc.stub.ClientCalls#blockingServerStreamingCall(io.grpc.Channel, io.grpc.MethodDescriptor<ReqT,RespT>, io.grpc.CallOptions, ReqT)
call, which in turn uses
BlockingResponseStream
. There is no way to reach theio.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/ClientStreamObserverThe other approach could be to implement
AutoCloseable
from Java with this iteratorThere is also a comment on the Iterator implementation class
The text was updated successfully, but these errors were encountered: