Exception while closing command context, Execution 7445 doesn't exit, Execution is Null

Hi there,
I have a simple process, where i have a service task, and inside which I am correlating a message start event, with message name. My two bpmns go like this:

Inside my service task, when i am trying to get or set variable from runtimeService, using below code:
this.runtimeService.getVariable(this.delegateExecution.getId(), "timeStamp")!=null

I am getting the following error:
Exception while closing command context, Execution 74456 doesn’t exist.

Note: My service task is a never ending one.

Try using:
delegateExecution.getVariable("timeStamp");

to get the variable.

Hi @Niall,

I tried using your method, but i facing following issue:
Cannot work with serializers outside of command context.Process engine exception
Thanks
-SatyaRam

Hi @Niall,

Here is full error:
org.camunda.bpm.engine.ProcessEngineException: ENGINE-03041 Cannot work with serializers outside of command context. at org.camunda.bpm.engine.impl.db.EnginePersistenceLogger.serializerOutOfContextException(EnginePersistenceLogger.java:390) at org.camunda.bpm.engine.impl.persistence.entity.util.TypedValueField.getSerializers(TypedValueField.java:214) at org.camunda.bpm.engine.impl.persistence.entity.util.TypedValueField.setValue(TypedValueField.java:112) at org.camunda.bpm.engine.impl.persistence.entity.VariableInstanceEntity.<init>(VariableInstanceEntity.java:126) at org.camunda.bpm.engine.impl.persistence.entity.VariableInstanceEntity.create(VariableInstanceEntity.java:145) at org.camunda.bpm.engine.impl.persistence.entity.VariableInstanceEntityFactory.build(VariableInstanceEntityFactory.java:30) at org.camunda.bpm.engine.impl.persistence.entity.VariableInstanceEntityFactory.build(VariableInstanceEntityFactory.java:24) at org.camunda.bpm.engine.impl.core.variable.scope.AbstractVariableScope.setVariableLocal(AbstractVariableScope.java:368) at org.camunda.bpm.engine.impl.core.variable.scope.AbstractVariableScope.setVariable(AbstractVariableScope.java:341) at org.camunda.bpm.engine.impl.core.variable.scope.AbstractVariableScope.setVariable(AbstractVariableScope.java:309) at com.hcc.hpi.modeller_toolbox_services_mqtt.MqttSubscriber.messageArrived(MqttSubscriber.java:213) at org.eclipse.paho.client.mqttv3.internal.CommsCallback.deliverMessage(CommsCallback.java:475) at org.eclipse.paho.client.mqttv3.internal.CommsCallback.handleMessage(CommsCallback.java:379) at org.eclipse.paho.client.mqttv3.internal.CommsCallback.run(CommsCallback.java:183) at java.lang.Thread.run(Unknown Source)

can you show the full code of your delegate.
Also what kind of variable are you expecting back from the contentxt?

Hi @Niall

If you observe clearly, I have two bpmns, one with just once single task, which is a service Class and it doesn not have any end text, inside this service class, i am creating a thread, which internally connects with Mqtt boker and listens to it, the thread keeps on running, meaning my service task of bpmn1 doesn’t end, I am able to correlate with the message event, and create process variable for the bpmn2 from this service class, however when i am trying to create process variable for the first process, it is throwing me error, execution id is null, The service class implementation is as below:

public void execute(DelegateExecution execution) throws Exception {

	try {
		RuntimeService runtimeService=execution.getProcessEngine().getRuntimeService();


		MqttSubscriberServiceTask mqtt_camunda_service_task = new MqttSubscriberServiceTask();

		org.camunda.bpm.model.bpmn.impl.instance.ServiceTaskImpl startEvent = (org.camunda.bpm.model.bpmn.impl.instance.ServiceTaskImpl) execution.getBpmnModelElementInstance();

		ExtensionElements extensionElements = startEvent.getExtensionElements();
		Collection<CamundaProperty> properties = extensionElements.getElementsQuery()
				.filterByType(CamundaProperties.class)
				.singleResult()
				.getCamundaProperties();

		String dmnName = null;
		String mqttVariableName = null;
		String mqttBrokerEndPoint = null;

		for (CamundaProperty property : properties) {
			String name = property.getCamundaName();
			String value = property.getCamundaValue();
			switch (name) {
				case DMNNAME:
					dmnName = value;
					break;
				case MQTTVARIABLENAME:
					mqttVariableName = value;
					break;
				case MQTTBROKERENDPOINT:
					mqttBrokerEndPoint = value;
					break;
			}
		}

		// MQTT Logic
		// setting the process variables with the received Message
		String mqttMessage = mqtt_camunda_service_task.subscribeWithBrokers(mqttBrokerEndPoint, execution, mqttVariableName, runtimeService);

		if (mqttMessage == "-1") {
			throw new RuntimeException(
					"Error: MQTT Broker Connection failed - Invalid Broker IP Address :: Contact Administrator.");
		} else if (mqttMessage == "-2") {
			throw new RuntimeException("Error: Exception occured in Thread Processing  :: Contact Administrator.");
		}

	} catch (Exception e) {
		e.printStackTrace();
	}
}

public String subscribeWithBrokers(String mqttBrokerEndPoint, DelegateExecution execution, String mqttVariableName, RuntimeService runtimeService) {

	try {
		// 1.Subscribe to the broker upon activation in a new Thread
		// logger.info("Inside MqttSubscriberServiceTask :: Subscribing to the broker
		// upon activation in a new Thread");
		MqttSubscriber subscriber = new MqttSubscriber(syncObj, receivedMsg, mqttVariableName, mqttBrokerEndPoint, execution, runtimeService);
		subscriber.subscribe();
	
	} catch (Exception e) {
		logger.error("Exception occured in subscribeWithBrokers:: " + e.getMessage());
		return "-2";
	}
	return receivedMsg.toString();
}

This is my javadelegate class, which internally creates a thread and calls subscribe method of other class, inside my MqttSubscribe class, i am trying to correlate with the message start event, and also I am creating process variable for my BPMN1.

        this.runtimeService.getVariable(this.delegateExecution.getId(), "LOL");


  runtimeService.createMessageCorrelation("satyaRam").setVariable("MQTT", message.toString()).setVariable("rootId", delegateExecution.getId()).setVariable("tailingData", collection).setVariable("deltaRegion", deltaRegion).setVariable("setCondition", setCondition).setVariable("timeStamp", now).setVariable("previousValue", previousValue).correlate();`

I’m beginner on camunda, I face on this issue, if anyone have an idea your help will be very helpful

3:35:47.789 [main] DEBUG org.camunda.bpm.engine.cmd - ENGINE-13011 closing existing command context
23:35:47.801 [main] ERROR org.camunda.bpm.engine.context - ENGINE-16004 Exception while closing command context: execution 4 doesn’t exist: execution is null
org.camunda.bpm.engine.exception.NullValueException: execution 4 doesn’t exist: execution is null
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
at org.camunda.bpm.engine.impl.util.EnsureUtil.generateException(EnsureUtil.java:394)
at org.camunda.bpm.engine.impl.util.EnsureUtil.ensureNotNull(EnsureUtil.java:55)
at org.camunda.bpm.engine.impl.util.EnsureUtil.ensureNotNull(EnsureUtil.java:50)
at org.camunda.bpm.engine.impl.cmd.GetExecutionVariableTypedCmd.execute(GetExecutionVariableTypedCmd.java:56)
at org.camunda.bpm.engine.impl.cmd.GetExecutionVariableTypedCmd.execute(GetExecutionVariableTypedCmd.java:33)
at org.camunda.bpm.engine.impl.interceptor.CommandExecutorImpl.execute(CommandExecutorImpl.java:28)
at org.camunda.bpm.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:110)
at org.camunda.bpm.engine.impl.interceptor.ProcessApplicationContextInterceptor.execute(ProcessApplicationContextInterceptor.java:70)
at org.camunda.bpm.engine.impl.interceptor.CommandCounterInterceptor.execute(CommandCounterInterceptor.java:35)
at org.camunda.bpm.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:33)
at org.camunda.bpm.engine.impl.RuntimeServiceImpl.getVariableTyped(RuntimeServiceImpl.java:350)
at org.camunda.bpm.engine.impl.RuntimeServiceImpl.getVariableTyped(RuntimeServiceImpl.java:345)
at com.example.workflow.jackson.JacksonConfiguratorTest.shouldSerializeJsonCorrectly(JacksonConfiguratorTest.java:54)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:55)
at org.camunda.bpm.engine.test.ProcessEngineRule$1.evaluate(ProcessEngineRule.java:176)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:221)
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54)
23:35:47.804 [main] DEBUG org.camunda.bpm.engine.tx - ENGINE-11002 firing event rollback…
23:35:47.804 [main] DEBUG org.camunda.bpm.engine.tx - ENGINE-11002 rolling back the persistence session…
23:35:47.805 [main] DEBUG org.camunda.bpm.engine.tx - ENGINE-11004 Firing event rolled back
23:35:47.806 [main] DEBUG org.apache.ibatis.transaction.jdbc.JdbcTransaction - Resetting autocommit to true on JDBC Connection [conn0: url=jdbc:h2:mem:camunda user=SA]
23:35:47.806 [main] DEBUG org.apache.ibatis.transaction.jdbc.JdbcTransaction - Closing JDBC Connection [conn0: url=jdbc:h2:mem:camunda user=SA]
23:35:47.807 [main] DEBUG org.apache.ibatis.datasource.pooled.PooledDataSource - Returned connection 537524656 to pool.
23:35:47.807 [main] DEBUG org.camunda.bpm.engine.cmd - ENGINE-13006 Finishing command -------------------- GetExecutionVariableTypedCmd ----------------------
23:36:04.958 [main] DEBUG org.camunda.bpm.engine.test - annotation @Deployment deletes deployment for JacksonConfiguratorTest.shouldSerializeJsonCorrectly
23:36:04.959 [main] DEBUG org.camunda.bpm.engine.cmd - ENGINE-13005 Starting command -------------------- DeleteDeploymentCmd ----------------------
23:36:04.959 [main] DEBUG org.camunda.bpm.engine.cmd - ENGINE-13009 opening new command context