grpc-java icon indicating copy to clipboard operation
grpc-java copied to clipboard

Clean up stream after AbstractClientStream.inboundTransportError()

Open madongfly opened this issue 11 years ago • 8 comments

Otherwise the stream object will still be held in the stream map of OkHttpClientTransport.

madongfly avatar Apr 08 '15 10:04 madongfly

What calls to inboundTransportError are you concerned about? The only one I could find that had issue was in AbstractClientStream. The ones in Http2ClientStream didn't seem like they would cause problem.

For the one in AbstractClientStream, it seems like we just need a sendCancel() like is done in Http2ClientStream.

ejona86 avatar Apr 08 '15 20:04 ejona86

@ejona86, actually I don't think the calling of inboundTransportError in AbstractClientStream will ever happen (the inboundPhase() == Phase.HEADERS case should have been caught by transportDataReceived).

I concerned the case in Http2ClientStream, we can not depends on sendCancel() to remove the stream since it is only called if we haven't seen endOfStream.

madongfly avatar Apr 09 '15 06:04 madongfly

Looking at this more, sendCancel() isn't necessary for stream removal (it is necessary to inform the server though). It seems we can just finish the stream when we receive endOfStream in OkHttpClientStream; delaying until OkHttpClientStream.remoteEndClosed() is unnecessary as there is no need to keep the stream alive.

But this does expose that we don't handle early server response. If the server responds before the client half-closes, then the client may never halfClose and OkHttpClientStream.remoteEndClosed() just removes the stream from 'streams'. It seems we should send RST_STREAM in that case and make sure to not send anything further for the stream.

ejona86 avatar Apr 09 '15 23:04 ejona86

@ejona86 I looked into the problem more deeply, so actually in our current implementation, we won't receive a data frame with end-of-stream, the end-of-stream will always be in a header frame (the Trailer), right? Is this required by our protocol? if so, we should clean up our stream classes, since there are many data frame handling involves end-of-stream, which is confusion.

madongfly avatar Apr 12 '15 13:04 madongfly

Normal responses will only have end of stream on the last HEADERS. However, for proxy-genereated errors, that isn't the case. And we would need to support doing something sane for such errors.

ejona86 avatar Apr 12 '15 15:04 ejona86

It turned out that we can't finish the stream before the Http2ClientStream handles the data, because we may not know the correct status yet, so alternatively, I chose to remove the streams for the error cases after the super-class's handling. PR is coming.

And for the early server half-close case, I split it to #300.

madongfly avatar Apr 14 '15 08:04 madongfly

@madongfly, why wouldn't we know the correct status? If the server sends endOfStream, then nothing that happens after that point should change the status, with the exception of cancellation. Could you point out where we need to set the status after inbound endOfStream on client-side?

ejona86 avatar Apr 14 '15 15:04 ejona86

@ejona86 We extract the status from the trailers: https://github.com/grpc/grpc-java/blob/c3e8dae6ce604dfdcd8fc0eb0f7b0e2303e48a98/core/src/main/java/io/grpc/transport/Http2ClientStream.java#L161, Unless we also extract it in OkHttpClientStream, but I don't like the duplicate operation.

madongfly avatar Apr 15 '15 01:04 madongfly