GRPC error `Only one write can be pending at a time`

402 views
Skip to first unread message

tom....@gmail.com

unread,
Nov 23, 2018, 10:30:28 AM11/23/18
to grpc.io

Hi Everyone,

I'm using grpc in combination with rx observables and now I'm running into
an issue where I sometimes get the following exception:

System.InvalidOperationException
Message=Only one write can be pending at a time
at Grpc.Core.Internal.AsyncCallServer`2.CheckSendAllowedOrEarlyResult()

I've been searching for what this means and how to resolve this and came
across a stack overflow post that mentions that there can be only one in-flight
message at any one time. However, I think I did that with my implementation:

public override Task MachineStatusStream(
    StatusStreamRequest request,
    grpc.IServerStreamWriter<StatusStreamResponse> responseStream,
    grpc.ServerCallContext context)
{
    return _alarmPresenter.AlarmStatusStream()
        .Select(status => status.ToGrpc())
        .Select(status => new StatusStreamResponse { Status = status })
        .ForEachAsync(response =>
            responseStream.WriteAsync(response).Wait(context.CancellationToken));
}

Isn't the `.Wait()` in the write async enough to guarantee that the write is finished?

Any pointers or help would be highly appreciated!

Best regards,

Tom

Robert Engels

unread,
Nov 23, 2018, 10:38:56 AM11/23/18
to tom....@gmail.com, grpc.io
You are using foreachasync so each (multiple in parallel) will perform the write before the wait is hit, which is not valid. Just use foreach instead and drop the wait, or sync on the write. 
--
You received this message because you are subscribed to the Google Groups "grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+u...@googlegroups.com.
To post to this group, send email to grp...@googlegroups.com.
Visit this group at https://groups.google.com/group/grpc-io.
To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/6555421c-5c63-472c-adc6-0e1e56ad48a4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages