An application which utilizes batch processing of the payload throws exceptions and specifically, "Cannot open a new cursor on a closed stream" as demonstrated below.
[2019-11-08 02:21:21.727] ERROR org.mule.service.scheduler.internal.AbstractRunnableFutureDecorator [[MuleRuntime].io.06: [support-batch-app].batch-management-work-manager @1a921b3c]: event:72578310-01ce-11ea-bf89-06204e2cfac4 Uncaught throwable in task [support-batch-app].batch-management-work-manager @1a921b3c - com.mulesoft.mule.runtime.module.batch.internal.engine.DefaultBatchEngine$$Lambda$4319/964909106 java.util.concurrent.ExecutionException: org.mule.runtime.api.serialization.SerializationException: Could not serialize object at java.util.concurrent.FutureTask.report(FutureTask.java:122) at java.util.concurrent.FutureTask.get(FutureTask.java:192) at org.mule.service.scheduler.internal.AbstractRunnableFutureDecorator.doRun(AbstractRunnableFutureDecorator.java:118) at org.mule.service.scheduler.internal.RunnableFutureDecorator.run(RunnableFutureDecorator.java:54) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748) Caused by: org.mule.runtime.api.serialization.SerializationException: Could not serialize object at org.mule.runtime.core.internal.serialization.AbstractSerializationProtocol.serialize(AbstractSerializationProtocol.java:63) at com.mulesoft.mule.runtime.module.batch.internal.engine.DefaultBatchJobInstanceStore.doStore(DefaultBatchJobInstanceStore.java:305) at com.mulesoft.mule.runtime.module.batch.internal.engine.DefaultBatchJobInstanceStore.update(DefaultBatchJobInstanceStore.java:109) at com.mulesoft.mule.runtime.module.batch.internal.engine.DefaultBatchEngine.finallyOnFinishJobInstance(DefaultBatchEngine.java:436) at com.mulesoft.mule.runtime.module.batch.internal.engine.DefaultBatchEngine.lambda$0(DefaultBatchEngine.java:400) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at org.mule.service.scheduler.internal.AbstractRunnableFutureDecorator.doRun(AbstractRunnableFutureDecorator.java:111) ... 4 more Caused by: com.esotericsoftware.kryo.KryoException: java.lang.IllegalStateException: Cannot open a new cursor on a closed stream Serialization trace: variables (com.mulesoft.mule.runtime.module.batch.BatchEvent) event (com.mulesoft.mule.runtime.module.batch.internal.DefaultBatchJobInstance) at com.esotericsoftware.kryo.serializers.ObjectField.write(ObjectField.java:101) at com.esotericsoftware.kryo.serializers.FieldSerializer.write(FieldSerializer.java:508) at com.esotericsoftware.kryo.Kryo.writeObject(Kryo.java:575) at com.esotericsoftware.kryo.serializers.ObjectField.write(ObjectField.java:79) at com.esotericsoftware.kryo.serializers.FieldSerializer.write(FieldSerializer.java:508) at com.esotericsoftware.kryo.Kryo.writeClassAndObject(Kryo.java:651) at com.mulesoft.mule.runtime.core.internal.serialization.kryo.protocol.KryoSerializationProtocol.lambda$0(KryoSerializationProtocol.java:97) at com.mulesoft.mule.runtime.core.internal.serialization.kryo.protocol.KryoSerializationProtocol.onOutput(KryoSerializationProtocol.java:103) at com.mulesoft.mule.runtime.core.internal.serialization.kryo.protocol.KryoSerializationProtocol.doSerialize(KryoSerializationProtocol.java:97) at com.mulesoft.mule.runtime.core.internal.serialization.kryo.protocol.KryoSerializationProtocol.doSerialize(KryoSerializationProtocol.java:90) at org.mule.runtime.core.internal.serialization.AbstractSerializationProtocol.serialize(AbstractSerializationProtocol.java:61) ... 11 more
When looking closer at the log files, warnings like the ones below may be observed to include "Batch job is being created with variable supportVariable which is a streaming value. Streaming values are potentially large."
2019-11-08 03:22:06,231 [[MuleRuntime].io.81: [support-batch-app].main-impl-scheduler:trigger.BLOCKING @7f7611d5] WARN com.mulesoft.mule.runtime.module.batch.BatchEvent - Batch job is being created with variable supportVariable which is a streaming value. Streaming values are potentially large, and thus should not be part of a batch variable but a batch record. This is bad practice that will threaten the stability and performance of the application.
To rephrase, the variable must be serialized from a stream before being used inside a batch.
The following DataWeave function, as explained here: DataWeave - write can be used:
<set-variable variableName="supportVariable" value="#[write(payload, 'application/json')]" mimeType="application/json" encoding="UTF-8/>
Important: By the execution of the DataWeave write() function, the variable's value will be serialized, occupying Java heap memory. Therefore, it may change the requirements for application deployment.
Disclaimer 2: This solution provides a suggestion that should be considered in conjunction with your specific use-case and requirements and does not represent a complete solution for all circumstances.
001123125

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.