Thanks for your help in advance! Any advises are much appreciated.
I’m getting “java.lang.IllegalStateException: Operation allowed only while eventLoop is running” Only in production, not in dev or preprod, only occasionally, seemingly random from different places. There is no Async promise or child workflows.
The exception were usually from saveEntity() invoked from different places of workflow class inherits BaseRequestWorkflow
maxim,
The activity stubs are private final per workflow instance as shown above. The workflow and activities instances are registered with springboot Config as below. Would that be an issue? It works fine mostly, except for the issue in the description.
public class WorkerConfig {
@Autowired
private WorkflowClient workflowClient;
@Autowired
Map<String, UserRequestType> userRequestTypeRegistry;
@Autowired
private SystemActivityImpl systemActivity;
@Autowired
private EmailActivityImpl emailActivity;
@Value("${temporal.server.queue.name:default}")
private String serverQueueName;
@Bean
public String serverQueueName() {
return serverQueueName;
}
@Bean
public WorkerFactory workerFactory() {
// WorkerFactory that can be used to create workers.
WorkerFactory factory = WorkerFactory.newInstance(workflowClient);
Worker worker = factory.newWorker(serverQueueName);
worker.registerWorkflowImplementationTypes(TestConfigWorkflow.class);
for (UserRequestType type : TestConfigWorkflow.getUserRequestTypes()) {
userRequestTypeRegistry.put(type.getType(), type);
}
worker.registerActivitiesImplementations(systemActivity);
worker.registerActivitiesImplementations(emailActivity);
factory.start();
return factory;
}
}
java.lang.IllegalStateException: Operation allowed only while eventLoop is running
at io.temporal.internal.statemachines.WorkflowStateMachines.checkEventLoopExecuting(WorkflowStateMachines.java:1313)
at io.temporal.internal.statemachines.WorkflowStateMachines.randomUUID(WorkflowStateMachines.java:899)
at io.temporal.internal.replay.ReplayWorkflowContextImpl.scheduleActivityTask(ReplayWorkflowContextImpl.java:202)
at io.temporal.internal.sync.SyncWorkflowContext.executeActivityOnce(SyncWorkflowContext.java:304)
at io.temporal.internal.sync.SyncWorkflowContext.executeActivity(SyncWorkflowContext.java:278)
at io.temporal.internal.sync.ActivityStubImpl.executeAsync(ActivityStubImpl.java:59)
at io.temporal.internal.sync.ActivityStubBase.execute(ActivityStubBase.java:39)
at io.temporal.internal.sync.ActivityInvocationHandler.lambda$getActivityFunc$0(ActivityInvocationHandler.java:83)
at io.temporal.internal.sync.ActivityInvocationHandlerBase.invoke(ActivityInvocationHandlerBase.java:60)
at jdk.proxy2/jdk.proxy2.$Proxy211.saveEntity(Unknown Source)
at com.company.ipp.temporal.worker.BaseRequestWorkflow.saveEntity(BaseRequestWorkflow.java:74)
at com.company.ipp.temporal.worker.VrlTestMachinePoolValidationProcessor.watchJob(VrlTestMachinePoolValidationProcessor.java:266)
at com.company.ipp.temporal.worker.VrlTestMachinePoolValidationProcessor.processActivity(VrlTestMachinePoolValidationProcessor.java:196)
at com.company.ipp.temporal.worker.BaseRequestWorkflow.process(BaseRequestWorkflow.java:208)
at com.company.ipp.temporal.worker.BaseRequestWorkflow.traverse(BaseRequestWorkflow.java:171)
--
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at io.temporal.internal.sync.POJOWorkflowImplementationFactory$POJOWorkflowImplementation$RootWorkflowInboundCallsInterceptor.execute(POJOWorkflowImplementationFactory.java:342)
at io.temporal.internal.sync.POJOWorkflowImplementationFactory$POJOWorkflowImplementation.execute(POJOWorkflowImplementationFactory.java:317)
at io.temporal.internal.sync.WorkflowExecutionHandler.runWorkflowMethod(WorkflowExecutionHandler.java:70)
at io.temporal.internal.sync.SyncWorkflow.lambda$start$0(SyncWorkflow.java:135)
at io.temporal.internal.sync.CancellationScopeImpl.run(CancellationScopeImpl.java:102)
at io.temporal.internal.sync.WorkflowThreadImpl$RunnableWrapper.run(WorkflowThreadImpl.java:107)
at io.temporal.worker.ActiveThreadReportingExecutor.lambda$submit$0(ActiveThreadReportingExecutor.java:53)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
at java.base/java.lang.Thread.run(Thread.java:833)
Are you sure activity stubs defined in BaseRequestWorkflow are not being reused across multiple executions? Do you get same error if you create the stub in saveEntity method each time instead of reusing?
All activity stubs are private fields (shown below) of in the Workflow class, which is submitted with the submit() method above by workflowClient. The Exception happens not often and there is not a clear pattern how to reproduce it. The activity components themselves are instantiated by sprintboot framework.
Should the activity stubs be created differently, not like this?
public abstract class BaseRequestWorkflow implements GenericRequestWorkflow {
private final SystemActivity systemActivity =
Workflow.newActivityStub(
SystemActivity.class,
ActivityOptions.newBuilder()
.setStartToCloseTimeout(Duration.ofMinutes(1))
.setRetryOptions(RetryOptions.newBuilder()
.setMaximumAttempts(2)
.build())
.build());
it’s difficult to create a standalone case that reproduces the symptom. Could you instruct on how to write code to detect if the eventLoop is running in the current thread/context? It would help me troubleshooting. Thanks