On Friday, 7 July 2017 17:11:01 UTC+7, [email protected] wrote:
>
> Hi.
>
> Is there a preferred way of implementing server side timeouts with the 
> generated Go gRPC code? I'm using bidirectional streaming, with the 
> extended request tied to a database transaction. I need to ensure database 
> transactions are not held open more than a few seconds.
>
> Doing this in Go, my best option seems to be to create a new context using 
> context.WithTimeout(stream.Context(), dur) and using that. If I use this 
> context when beginning the transaction, it will cause the transaction to 
> rollback on the timeout. This does mean that the gRPC handler may keep 
> running for some time, blocked on a stream.Recv or similar. So I can also 
> use a goroutine for the main body of my handler, and wait of either the 
> goroutine to complete or my context to be cancelled. Technically this would 
> leak the goroutine I think (if blocked on stream.Recv or similar), although 
> I think all that should clean up when the stream.Context() gets cancelled.
>
> Or maybe there is something built in to the gRPC library that I missed?
>

I've also tried installing an inTapHandle, which adds a timeout to the 
context. Unfortunately with this approach, it seems that this shuts down 
communication too early and no error returned to the client, which can 
leave a client hanging indefinitely trying to receive a message.

-- 
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 [email protected].
To post to this group, send email to [email protected].
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/1bc22ae4-c6b9-4d0f-9fc9-c87eea3a8f4b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to