Skip to content
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

Why I cannot get messages in real-time but only when the browser closes the pending call? #128

Closed
frederikhors opened this issue Jul 4, 2021 · 5 comments

Comments

@frederikhors
Copy link

I'm trying to use protobuf-ts with server streaming (https://github.com/improbable-eng/grpc-web/tree/master/go/grpcweb in Golang) but I don't get messages from server until connection is closed.

I'm using Svelte 3 like this:

<script lang="ts">
	import { onDestroy, onMount } from 'svelte';

  const transport = new GrpcWebFetchTransport({ baseUrl: '/', format: 'binary' });

  const service = new EventServiceClient(transport)

	const abortController = new AbortController();

	onMount(async () => {
		const call = service.flow({}, { abort: abortController.signal });

    for await (const response of call.responses) {
			console.log('got another response!', response);
		}
	});

	onDestroy(() => abortController.abort());
</script>

The call in in pending state for about 2.2 min. After that I get all messages logged in console.

image

I need them in real-time!

Where am I doing wrong?

@frederikhors
Copy link
Author

I think this is due to: volatiletech/authboss#325.

@frederikhors
Copy link
Author

I will close this issue ASAP.

@timostamm
Copy link
Owner

For server streaming, the response is read in chunks. The server must send the response chunks out as soon as possible, not wait for the response to finish.

XMLHttpRequest has a limitation, the only way for clients to read the response as chunks is to use a text-based format. That's why grpc-web has the text format.

It is possible that the libraries you are using have better support for the text format. I guess the chance is rather slim though. It is more likely that the authboss middleware is just not written with streaming responses in mind.

@frederikhors
Copy link
Author

frederikhors commented Jul 6, 2021

XMLHttpRequest has a limitation, the only way for clients to read the response as chunks is to use a text-based format. That's why grpc-web has the text format.

If I remove that library from my backend server protobuf-ts streaming works with binary format too, not only text.

Here is the code for that middleware: https://github.com/volatiletech/authboss/blob/master/client_state.go#L123.

@timostamm
Copy link
Owner

I am sorry you got stuck with this, but I'm afraid there is nothing we can do from the protobuf-ts side. This needs some debugging of the go code to pinpoint the cause.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants