mrpmorris / Fluxor

Fluxor is a zero boilerplate Flux/Redux library for Microsoft .NET and Blazor.
MIT License
1.22k stars 139 forks source link

grpc server stream within effect method get blocked #449

Closed althunibat closed 8 months ago

althunibat commented 10 months ago
[EffectMethod]
    public async Task RegisterTenant(RegisterTenant action, IDispatcher dispatcher) {
        try {
            using var call = _client.RegisterTenant(new RegisterTenantRequest {
                CorrelationId = _state.Value.CorrelationId,
                Email = action.Email,
                FirstName = action.FirstName,
                LastName = action.LastName,
                Name = action.TenantName
            }, deadline: DateTime.UtcNow.Add(TimeSpan.FromMinutes(10)));
            await foreach (var evt in call.ResponseStream.ReadAllAsync()) {
                _logger.LogInformation("received {Event} ", typeof(RegisterTenantResponse));
                if (evt.Status == NexusGate.Grpc.RegistrationStatus.Started)
                    dispatcher.Dispatch(new RegistrationStarted());
                else if (evt.Status == NexusGate.Grpc.RegistrationStatus.Completed)
                    dispatcher.Dispatch(new RegistrationCompleted());
                else if (evt.Status == NexusGate.Grpc.RegistrationStatus.EmailVerified)
                    dispatcher.Dispatch(new EmailVerified());
                else if (evt.Status == NexusGate.Grpc.RegistrationStatus.Failed) {
                    _snackbar.Add(evt.StatusText);
                    dispatcher.Dispatch(new RegistrationFailed());
                }
            }
        }
        catch (RpcException e) {
            _logger.LogError("RegistrationEffects-RegisterTenant", e);
        }
    }

in a blazor wasm application, given above call is an effect method that calls grpc server, with server streaming response. what is happening, the await foreach is blocked forever, or in this case, deadline reached.

if the same call happening within component initialization, evrything works fine.

any clue what should be done to make it work?

althunibat commented 10 months ago

it seems, i misconfigured the grpc client in blazor; i should configure it like:

GrpcWebMode.GrpcWebText configures base64-encoded content. Required for server streaming calls in browsers.

https://learn.microsoft.com/en-us/aspnet/core/grpc/grpcweb?view=aspnetcore-7.0#configure-grpc-web-with-the-net-grpc-client

mrpmorris commented 8 months ago

Is it okay to close this?