n8n-io/n8n

Problem sending Binary Data with "Respond to Webhook"

fjodorsch opened this issue · 6 comments

Bug Description

Sometimes,
When responding with large Binary Data (> ca. 2 MB) with the "Respond to Webhook" Node
the following Error is logged to the n8n console.

Error: Cannot set headers after they are sent to the client
    at new NodeError (node:internal/errors:405:5)
    at ServerResponse.setHeader (node:_http_outgoing:648:11)
    at ServerResponse.header (/usr/local/lib/node_modules/n8n/node_modules/express/lib/response.js:795:10)
    at ServerResponse.send (/usr/local/lib/node_modules/n8n/node_modules/express/lib/response.js:175:12)
    at ServerResponse.json (/usr/local/lib/node_modules/n8n/node_modules/express/lib/response.js:279:15)
    at Object.sendSuccessResponse (/usr/local/lib/node_modules/n8n/dist/ResponseHelper.js:28:17)
    at /usr/local/lib/node_modules/n8n/dist/WebhookHelpers.js:114:24
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
Error: Premature close
Error with Webhook-Response for execution "3019974": "Premature close"

And if the File were an Image for example it would only load like half way.
Chrome logs:

Failed to load resource: net::ERR_HTTP2_PROTOCOL_ERROR

Workaround:

In the Webhook node, use

  • Respond
    • When Last Node Finishes
  • Response Data
    • First Entry Binary

To Reproduce

Workflow to showcase:

Test.json

Expected behavior

work

Operating System

Official Docker Image running on Ubuntu

n8n Version

1.38.2

Node.js Version

18.19.1

Database

PostgreSQL

Execution mode

main (default)

This is likely the same issue we've been trying to fix in #9063.

I've just created a new docker image n8nio/n8n:fix-9291 from that branch.
Can you try switching to this docker image to see if it fixes the issue for you?

Ok, I tested it with the Image n8nio/n8n:fix-9291 on my laptop using the same workflow and
it works.

Edit: Only because I didn't use - N8N_DEFAULT_BINARY_DATA_MODE=filesystem

Wait, I tested it again but with

- N8N_DEFAULT_BINARY_DATA_MODE=filesystem

and it happened again

We fixed a race-condition, and we have published a new docker image on the same tag n8nio/n8n:fix-9291.
Can you please pull the docker image again, and check if the issue is resolved for you 🙏🏽 ?

#9063 is merged and will be included in the next release tomorrow.

Fix got released with n8n@1.41.0