Workflow block throws 413 error when referencing large data set , and 504 gateway error

Hello @Darren ,

I am facing similar issue , im in self hosting retool. my block gets data from previous sql block. Data is like array of 106080 items.

Thanks for reaching out, @mpmohi! What kind of resource query is that? It looks like it might be a Query JSON with SQL block, in which case the issue likely is related to the size of the array being passed in. The size of the payload being passed between blocks has a hard ceiling of 100MB, but this can be lower in practice depending on the details of your setup. You might be able to find a relevant error in your logs if that is the case.

In general, though, I'd recommend chunking the array and processing it in steps, if at all possible.

So the limit also applicable in self host version ? I changed it to 40m like this post and then this block seems working . ( though I get 502 gateway error : Getting "Internal Error running a block: Error: An internal server error occurred" error - #9 )

In some cases, yes. Some of our middleware will throw an error that isn't configurable via environment variables. If you've already had success after updating the client_max_body_size in nginx, though, the original error was likely being thrown by your https-portal container.

I can jump into the other topic that you've linked and help you out over there, assuming the 413 has been resolved!

hi,
Yes 413 is resolved with nginx, in my case I am not using https-portal configuration they are commented.

If you can help with gateway issue that would be very helpful. Thanks

Can you clarify which environment variable you updated, then? Was it RETOOL_CLIENT_MAX_BODY_SIZE?

I've also broken this out into a separate topic in order to consolidate the conversation!

Hi @Jack_T ,
{"data":null,"metadata":{},"error":"Internal Error running a block: Error: 504 Gateway Time-out"}

this is what I am getting when my python block has to process a lot of data. for moderate amount this workflow is running fine.

I am on self hosting running with docker. Can you tell what will be the value and process to set this variable.

some error logs:

workflow backend service

{"level":"info","message":{"http":{"method":"POST","url_base":"workflows-backend","url_path":"/api/workflow/runCodeInSandbox"},"type":"REQUEST_BEGIN"},"pid":156,"requestId":"b83344a4-67d2-4bcc-862d-bd838a969e9a","startTime":266955308.258865,"timestamp":"2025-09-11T07:10:13.534Z"}
{"level":"info","message":{"http":{"method":"POST","url_path":"http://code-executor:3004/api/executeCode"},"type":"CLIENT_REQUEST"},"pid":156,"requestId":"b83344a4-67d2-4bcc-862d-bd838a969e9a","sequelizeConnectionCount":1,"sequelizeCount":3,"startTime":266955308.258865,"timestamp":"2025-09-11T07:10:13.746Z"}
{"level":"info","message":{"http":{"method":"POST","request":{"time":536.5244278419912},"url_path":"http://code-executor:3004/api/executeCode"},"status":500,"type":"CLIENT_FINISH"},"pid":156,"requestId":"b83344a4-67d2-4bcc-862d-bd838a969e9a","sequelizeConnectionCount":1,"sequelizeCount":3,"startTime":266955308.258865,"timestamp":"2025-09-11T07:19:10.270Z"}
{"errorMsg":"{\"error\":true,\"message\":\"Internal server error\"}","level":"error","message":"hit error communicating with code executor","pid":156,"requestId":"b83344a4-67d2-4bcc-862d-bd838a969e9a","sequelizeConnectionCount":1,"sequelizeCount":3,"startTime":266955308.258865,"timestamp":"2025-09-11T07:19:10.271Z"}
{"errorType":"UNCAUGHT_ERROR","level":"error","message":"Global uncaught error","msg":"hit an unexpected error","pid":156,"requestId":"b83344a4-67d2-4bcc-862d-bd838a969e9a","sequelizeConnectionCount":1,"sequelizeCount":3,"stack":"Error: hit an unexpected error\n    at Pro.handleCodeExecutorError (/retool_backend/bundle/main.js:1590:7508)\n    at Pro.sendToCodeExecutor (/retool_backend/bundle/main.js:1590:4495)\n    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)\n    at async /retool_backend/bundle/main.js:9440:27173","startTime":266955308.258865,"timestamp":"2025-09-11T07:19:10.272Z"}
{"error":{"errorType":"UNCAUGHT_ERROR","msg":"hit an unexpected error","stack":"Error: hit an unexpected error\n    at Pro.handleCodeExecutorError (/retool_backend/bundle/main.js:1590:7508)\n    at Pro.sendToCodeExecutor (/retool_backend/bundle/main.js:1590:4495)\n    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)\n    at async /retool_backend/bundle/main.js:9440:27173"},"errorType":"INTERNAL_ERROR","level":"error","message":"Global uncaught error","msg":"Internal server error: hit an unexpected error","pid":156,"requestId":"b83344a4-67d2-4bcc-862d-bd838a969e9a","sequelizeConnectionCount":1,"sequelizeCount":3,"stack":"Error: hit an unexpected error\n    at Pro.handleCodeExecutorError (/retool_backend/bundle/main.js:1590:7508)\n    at Pro.sendToCodeExecutor (/retool_backend/bundle/main.js:1590:4495)\n    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)\n    at async /retool_backend/bundle/main.js:9440:27173","startTime":266955308.258865,"timestamp":"2025-09-11T07:19:10.273Z"}
{"error":{"errorType":"INTERNAL_ERROR","msg":"Internal server error: hit an unexpected error","stack":"Error: hit an unexpected error\n    at Pro.handleCodeExecutorError (/retool_backend/bundle/main.js:1590:7508)\n    at Pro.sendToCodeExecutor (/retool_backend/bundle/main.js:1590:4495)\n    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)\n    at async /retool_backend/bundle/main.js:9440:27173"},"level":"info","message":{"connectionCount":0,"http":{"method":"POST","request":{"size":48,"time":536.7389152500033},"status_code":500,"url_base":"workflows-backend","url_path":"/api/workflow/runCodeInSandbox"},"queryCount":3,"type":"REQUEST_FINISH"},"pid":156,"requestId":"b83344a4-67d2-4bcc-862d-bd838a969e9a","sequelizeConnectionCount":1,"sequelizeCount":3,"startTime":266955308.258865,"timestamp":"2025-09-11T07:19:10.273Z"}

executor log:

{"blockUuid":"2f9be163-3b70-4e57-9d08-1e459aaff8d9","level":"info","message":{"http":{"method":"POST","url_path":"http://workflows-backend:3000/api/workflow/runCodeInSandbox"},"type":"CLIENT_REQUEST"},"organizationId":"1","requestId":"b83344a4-67d2-4bcc-862d-bd838a969e9a","timestamp":"2025-09-11T07:10:13.511Z","workflowId":"6518144a-f871-4abe-b8f3-18367ce0cbfc","isSandboxLog":true}
{"dd":{"env":"production","service":"code_executor_service","span_id":"6209869500228144765","trace_id":"6750531415728968423"},"level":"info","message":{"http":{"method":"POST","url_base":"code-executor","url_path":"/api/executeCode"},"type":"REQUEST_BEGIN"},"pid":13,"requestId":"b83344a4-67d2-4bcc-862d-bd838a969e9a","startTime":266993733.246572,"timestamp":"2025-09-11T07:10:13.796Z"}
{"dd":{"env":"production","service":"code_executor_service","span_id":"6079438083464674602","trace_id":"6750531415728968423"},"level":"error","message":"Unhandled error in code executor /api/executeCode: Invalid string length","path":"/api/executeCode","pid":13,"requestId":"b83344a4-67d2-4bcc-862d-bd838a969e9a","startTime":266993733.246572,"timestamp":"2025-09-11T07:19:10.267Z"}
{"dd":{"env":"production","service":"code_executor_service","span_id":"6079438083464674602","trace_id":"6750531415728968423"},"level":"info","message":{"http":{"method":"POST","request":{"size":48,"time":536.473915375024},"status_code":500,"url_base":"code-executor","url_path":"/api/executeCode"},"type":"REQUEST_FINISH"},"pid":13,"requestId":"b83344a4-67d2-4bcc-862d-bd838a969e9a","startTime":266993733.246572,"timestamp":"2025-09-11T07:19:10.270Z"}
{"blockUuid":"2f9be163-3b70-4e57-9d08-1e459aaff8d9","level":"info","message":{"http":{"method":"POST","request":{"time":536.7706382210001},"url_path":"http://workflows-backend:3000/api/workflow/runCodeInSandbox"},"status":500,"type":"CLIENT_FINISH"},"organizationId":"1","requestId":"b83344a4-67d2-4bcc-862d-bd838a969e9a","timestamp":"2025-09-11T07:19:10.282Z","workflowId":"6518144a-f871-4abe-b8f3-18367ce0cbfc","isSandboxLog":true}
{"blockUuid":"2f9be163-3b70-4e57-9d08-1e459aaff8d9","error":"f.stdoutMessages is not iterable","level":"error","message":"Unexpected error processing runCodeInSandbox response","organizationId":"1","pluginId":"generateCombinationsWithDeny","responseBodyText":"{\"error\":true,\"message\":\"Internal server error\"}","timestamp":"2025-09-11T07:19:10.282Z","workflowId":"6518144a-f871-4abe-b8f3-18367ce0cbfc","isSandboxLog":true}
{"dd":{"env":"production","service":"code_executor_service","span_id":"9058968936145499500","trace_id":"1324309813884156452"},"jobId":"e86679bb-29bb-45a3-aabd-c8a6156b1906","level":"info","message":"Successfully ran the block","organizationId":"1","pid":13,"requestId":"0486ec76-4332-4082-b33a-5f1fc579f80b","startTime":266992827.598133,"timestamp":"2025-09-11T07:19:10.299Z","workflowId":"6518144a-f871-4abe-b8f3-18367ce0cbfc"}
{"dd":{"env":"production","service":"code_executor_service","span_id":"3288377331325977423","trace_id":"1324309813884156452"},"jobId":"e86679bb-29bb-45a3-aabd-c8a6156b1906","level":"info","message":{"http":{"method":"POST","request":{"size":567,"time":537.4141647210121},"status_code":200,"url_base":"code-executor","url_path":"/api/runBlock"},"type":"REQUEST_FINISH"},"organizationId":"1","pid":13,"requestId":"0486ec76-4332-4082-b33a-5f1fc579f80b","startTime":266992827.598133,"timestamp":"2025-09-11T07:19:10.304Z","workflowId":"6518144a-f871-4abe-b8f3-18367ce0cbfc"}

Thanks

Thanks for sharing relevant logs, @mpmohi. The primary culprit seems to be the following:

Unhandled error in code executor /api/executeCode: Invalid string length

This error is typically thrown whenever JSON.stringify tries to generate a string that exceeds the execution environment's memory limits or capabilities. For context, Retool automatically converts the output of every workflow block when sending it to the backend service.

You can increase the workflow's memory allocation via the WORKFLOW_MEMORY_LIMIT_MBS environment variable, but I'm not certain it will make a difference in this particular case. Would you be able to split up your data for processing?

hi @Darren :slight_smile:
So I increased the limit but issue persists. This is happening when any block is takinng more than 30s.

For the data split can I do this: a code block with it some loop block these will loop and do something and after doing go back to initial block and process

thanks

That's too bad, but I'm not really surprised. It was a bit of a reach.

Can you confirm this and share a screenshot of the error alongside any relevant logs? If there really is a consistent 30s timeout across all your workflow blocks, you are probably hitting a timeout threshold somewhere in your stack. The relevant configuration options in Nginx, for example, would be proxy_read_timeout, proxy_connect_timeout, or proxy_send_timeout.

hi @Darren ,

Adding proxy blocks to retool's nginx conf seems solve gateway issue. Though my block still couldn't complete running.

I set 1 hour in nginx and 1 hour on the block timeout. After running for several minutes I got:

" * data

  • metadata
  • errorHit unexpected internal error while executing your code. We will resolve this as soon as possible
    "

Just this error not anything else. My specific requirements require a long running block ( process couple hundrad milion data ) need couple of hour.

Do you think we can do this with retool ? if so what would be the best practice / way to do it

I can hop on a call with @retool team if needed

I'm glad to hear that updating your nginx configuration helped with the timeouts! As long as you are triggering the workflow in an asynchronous manner, it shouldn't have any issues running for multiple hours. I think the ceiling is something like 24 days.

That said, it's still possible to be bottlenecked by data transfers and memory allocation. It would probably be most helpful to take a look at your container logs when the workflow fails. If you do want to hop on a call, we host Office Hours every Tuesday and Thursday!

Have you had a chance to revisit this, @mpmohi? Or are you able to join Office Hours?

Hi @Darren ,
Thanks for following up. Client decided to move from retool. If I can in future I will be joining any of the office hours.

Thanks

1 Like