Trying to block on coroutine which is already blocked, most likely a wrong Context is used to do blocking call

Hi,

I’m seeing the following error in my workflow.

trying to block on coroutine which is already blocked, most likely a wrong Context is used to do blocking call (like Future.Get() or Channel.Receive()

My workflow looks something like this.

retryCtx := workflow.WithRetryPolicy(ctx, ...)
for ... {
    workflow.Go(ctx, func (ctx workflow.Context) {
        err := workflow.ExecuteActivity(retryCtx, ...).Get(retryCtx, nil)
        ...
    })
}

If I replace Get(retryCtx, nil) with Get(ctx, nil), the error goes away.

What does the error mean and why does retryCtx not work in this case? I guess I haven’t paid much attention to what context is passed to Get(). I always pass the same context that was passed to ExecuteActivity() to the Get() also.

This can admittedly get a little confusing, but basically by using .Get(retryCtx) you are blocking on the top-level workflow context inside the coroutine which you should not do. The whole reason to start a new coroutine with workflow.Go is to have a context you can make calls on (i.e. block on) that does not affect the top-level context.

The reason you can call ExecuteWorkflow with the top-level context is because that doesn’t block, it’s just extracting params (e.g. the retry policy). But .Get does block, so you need to use the context for the coroutine you are in.

Thanks for the explanation @Chad_Retz