tonic-web-wasm-client
tonic-web-wasm-client copied to clipboard
Stream request hangs until first message
Thanks for updating the library for proper stream support!
I'm building a gRPC client, that works both on native and on the web platform. I stumbled across the following bug:
#[wasm_bindgen_test]
async fn test_echo_pending() {
let mut client = EchoClient::default();
// The future below will only resolve once the server returns a first message.
client
.echo_stream(EchoRequest {
message: "SILENCE!".to_string(),
})
.await
.expect("success stream response")
.into_inner();
}
This behaviour is different from using tonic::transport::Channel.
Reproducer can be found at https://github.com/devashishdxt/tonic-web-wasm-client/commit/1036c3f3dc316240f7e11a36ae0c4626c7758fbd.
So it seems the request returns indeed does return a 200 (so no problem with this library per se nor with tonic-web; developer console), but the Promise returned by the fetch call is still pending:
fetch("http://localhost:50051/echo.Echo/EchoStream", {
"headers": {
"accept": "application/grpc-web+proto",
"accept-language": "en-GB,en",
"content-type": "application/grpc-web+proto",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "cross-site",
"sec-gpc": "1",
"x-grpc-web": "1"
},
"referrer": "http://127.0.0.1:8000/",
"referrerPolicy": "strict-origin-when-cross-origin",
"body": "\u0000\u0000\u0000\u0000\n\n\bSILENCE!",
"method": "POST",
"mode": "cors",
"credentials": "omit"
});
That's .. unexpected?
If the promise returned by the fetch call is pending until first message is received, there's very little we can do here. I'll look into it over the weekend.
Also, in the code that you published, you need to register a Waker when you return Poll::Pending so that your async runtime can start polling that future once it is ready. Current implementation will hang forever.
Closing this issue