-1

I'm using Mule 4.2 and Anypoint Studio 7.3.

I have a flow which has an HTTP request and scatter gather request. The HTTP request connector calls an API and returns a page size of 25. The API results are paged through by calling the same flow again using the flow reference connector until all of the results are retrieved.

Everytime it gets to the 25th API call it throws the error below. If I increase the page size to 100 then it brings everything back on the 14th call and completes successfully.

How do I fix this error? I feel its hitting a limit?

ERROR 2019-10-10 16:31:28,227 [[MuleRuntime].cpuLight.08: [test-upload].testRecordUploadFlow.CPU_LITE @55ed087c] [event: fd0fc8e0-eb72-11e9-a538-a44cc83a8228] org.mule.runtime.core.internal.exception.OnCriticalErrorHandler: 
********************************************************************************
Message               : Too many child contexts nested.

Error type            : MULE:CRITICAL
Element               : testRecordUploadFlow/processors/5 @ test-upload:test-upload.xml:60 (Scatter-Gather)
Element XML           : <scatter-gather doc:name="Scatter-Gather" doc:id="7c4bc7be-5205-4f0a-82c0-2b56e5c2afdb" maxConcurrency="500">

Thanks for any help

user3165854
  • 1,505
  • 8
  • 48
  • 100

1 Answers1

0

That happens because there is recursive flow reference. It is not recommended to use recursive flow references because it can easily led to a stack overflow error. You can increase the limit of recursion, but do that under your own risk. My recommendation is to refactor the application to avoid using recursion in flows.

aled
  • 21,330
  • 3
  • 27
  • 34
  • Do you know the best way to page through an API? The examples I saw used a choice with a flow reference to call the flow again in a loop. This API doesn't return the total number of records or pages so need to loop through each page until it returns an empty payload. – user3165854 Oct 16 '19 at 23:54
  • @user3165854 You will want to decouple your aggregator from your request flow. In your example, the request flow should only be concerned with performing the request and returning a result but you've tightly coupled the aggregator logic within your request logic. You only really have two options for an aggregator, either polling or event driven. – Chad Aug 22 '22 at 06:11