grpc / grpc-dart

The Dart language implementation of gRPC.
https://pub.dev/packages/grpc
Apache License 2.0
861 stars 271 forks source link

Is it possible to expose stream state to the app? It's vital for tracking http2 requests and make appropriate reconnect logic etc.... #706

Open vhunkalo opened 7 months ago

vhunkalo commented 7 months ago

https://github.com/dart-lang/http2/blob/master/lib/src/streams/stream_handler.dart

attached link to the code, how to expose StreamState?

vhunkalo commented 7 months ago

@aran @kevmoo @domesticmouse @munificent

aran commented 7 months ago

I'm sorry, I'm not sure how to help.

AFAIK this repository is in maintenance mode, so I'm not sure what might move this issue forward for you. Normally I'd advise elaborating more—what's your specific question, what have you tried so far, what are you trying to achieve big picture, is there example code you'd like to be able to write that you can't, etc.

vhunkalo commented 7 months ago

I'm using Dart gRPC and I need to intercept some specific call(sync bi-directional stream) and it's essential to know its status(ready/close etc...), without it, it's impossible to make some reconnect logic etc

vhunkalo commented 7 months ago

without it, I don't know exact moment when stream is ready or not, when it's broken for example due to the Internet switch from Wi-Fi to Celluar, and it's implemented but StreamState is private and it's impossible to use it, why? In Kotlin it's implemented perfectly and work perfect

vhunkalo commented 7 months ago

IMAGE 2024-04-29 21:47:24 StreamState is hidden,but it's essential data to be exposed for dev

vhunkalo commented 7 months ago

so the question, how with grpc library I can access http2 requests and track them in more detail to robust reconnecting/requests dequeuing etc... @aran

aran commented 7 months ago

I'm sorry, I don't know the answer. (I'm also not a maintainer of this repo).

vhunkalo commented 7 months ago

@mraleph could you please check this issue?

mraleph commented 7 months ago

Do you really need StreamState? What code would you write if you had access to that?

It has all this very specific information about the state of a specific HTTP/2 stream, rather than the state of the whole HTTP/2 connection. I am not sure I understand what it has to do with reconnect on network changes - it would seem you need to just track health of the whole connection.

vhunkalo commented 7 months ago

For example, I have bi-directional stream inside my gRPC channel, it is configured in the server to live only 15sec and then I need to reconnect, and I need to track state of my rpc call(stream) in more robust way having all states of this call, because now I don't have any info regarding this stream, whether it's live or not @mraleph

vhunkalo commented 7 months ago

@mraleph yes yes, I need information about specific HTTP2 stream inside of gRPC

vhunkalo commented 7 months ago

this stream is using for messages in chat app, it need a lot of reconnection/requests dequeueing etc..., so I need to know health of this specific stream to handle it appropriately, it's vital info and without it it's impossible to develop reliable chat app bacause health of the stream is hidden and impossible to expose it

could fork lib and adjust it by myself, but it's not good idea if lib could have ability to intercept specific calls in more detail

vhunkalo commented 7 months ago

so yes, I need to track health of specific HTTP2 stream inside gRPC channel, NOT whole channel

vhunkalo commented 7 months ago

so regarding the code @mraleph

if (stream.state == StreamState.ready) { requestStreeamController.add(request); } else if(stream.state == StreamState.terminated){reconnect();}

vhunkalo commented 7 months ago

@mraleph quick question, is it possible to adjust this thing in the gRPC library to make such info accessible for developers?

mraleph commented 7 months ago

I honestly don't know and I don't have any time to look into this. At this point you are better off forking and patching things in the way that makes it work for you.

vkammerer commented 5 months ago

We're evaluating gRPC for our flutter apps, and find it hard to find guidance and recommandations about how to implement it. One topic that seems to require attention is reconnection logic.

@aran you wrote

AFAIK this repository is in maintenance mode

Does that mean that grpc-dart is not the recommended / optimal way of implementing gRPC for mobile flutter clients? Is there another way to implement a gRPC client that would be robust, resilient, and able to talk to a Flutter app?

mosuem commented 5 months ago

I don't know what "maintenance mode" means exactly - it is maintained, if that is what it means. But there are no plans on adding new features, as the library is in a good state as is. For usage on grpc in general, I would advise the docs. For help on specific implementations, forums like stackoverflow.com might be a good place to get help.

aran commented 5 months ago

@mosuem that is exactly what I meant by maintenance mode. I apologize if that came across in a negative manner.

@vkammerer I can't speak to "the recommended" but I'm using this library for a Flutter app and it works so far and I don't think there's another realistic way to use grpc with a Flutter app.

The real trade is grpc vs. something else like hand-coded json or openapi. In particular, if you are targeting the web platform, caveats to grpc-web are that by default you lose being able to look at your data in web inspector without an additional browser plugin & configuration, and grpc-web doesn't support client streaming and bidirectional streams (and won't at least until Safari ships WebTransport).