A safe way to send a signal to a long-running workflow?

Hey guys, I have two long-running workflows.

I need to send a signal from A to B, but B can continue as new. In some cases where this happens, I receive an error.

I’m thinking of creating a locking mechanism, but I’m not sure if it’s the best way to do this."

What is the error? If you are using only WorkflowID to send signal there should be no problem in your case.

1 Like

The error I receive is:

  • Unable to signal external workflow because it was not found

I’m using only workflow id to send the signal. I’m trying to reproduce again, but I still haven’t managed to.

The workflow A is a parent, and workflow B is a child with a close policy set to PARENT_CLOSE_POLICY_ABANDON.

Make sure that the child is started before calling continue-as-new. See Best way to create an async child workflow - #2 by maxim

I call continue-as-new considering either the history size of 3000 or the continueAsNewSuggested parameter from the object returned by the workflowInfo function.

Since the child workflows were started at the beginning of the main workflow, they have already been initiated.

What would happen if the parent workflow calls continue-as-new and a child sends a signal at the exact moment when the new workflow has not yet started? Since we only have the old workflow with the continue-as-new status, this error Unable to signal external workflow because it was not found would occur, considering that it is part of a closed status

I don’t think this should be a problem, as continue-as-new is an atomic operation. The test server doesn’t implement this atomically, so the race condition you described could rarely appear in the unit testing only.

1 Like

So, thank you for your help :smile: