Will workflow method be processed first or Signal

I start my workflows like this :

WorkflowExecution execution = WorkflowClient.start(workflow::workflowmetod, data);

and inside workflow i save the data (original input) as a member variable.

subsequently i send many signals to workflow using

Myworkflow mywf = workflowClient.newWorkflowStub(Myworkflow .class, workflowId);
mywf.signal1();

This works perfect under normal scenario.

However under load, or when worker is not available immediately to process the newly submtited workflow and if the workflow is signalled as well in the mean while, i see that worker attempts to process the signal first prior to to the workflow method.
In my usecases, i need the inital input necessarily for processing the signals and i end up reading this as null.

Is there any way to ensure that the workflow method get invoked prior to the signal?

This seems some kind of race conditon at the start of workflow and worker gives priority to signals over the workflow method.

This is by design as there are use cases when it is necessary to know that signal was received before the workflow method started execution. So make sure that your code can handle signal callback to be invoked before the main workflow method without throwing NPE.

To be more precise, it is not even about knowing if the signal was received before the workflow execution. It is needed to ensure that signals are not lost if the main method decides to return. The most basic scenario is the main method returning a counter and a signal handler incrementing it.

So, if the signal handler is called before the main method for all already received signals, the counter’s value is guaranteed to be correct. In the opposite case, the value will always be 0.