Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task Runner Timeout When Testing Workflow (Circular JSON) #12235

Open
jimleuk opened this issue Dec 15, 2024 · 3 comments
Open

Task Runner Timeout When Testing Workflow (Circular JSON) #12235

jimleuk opened this issue Dec 15, 2024 · 3 comments
Labels
in linear Issue or PR has been created in Linear for internal review Released

Comments

@jimleuk
Copy link

jimleuk commented Dec 15, 2024

Bug Description

Believe I found an expected bug and edge-case which I was able to reproduce on both docker and cloud environments so thought it worth reporting.

The following workflow is a simple test which uses

  • "http" node to fetch an image
  • "extract to json" node to convert image to base64 string
  • sends the image data to an API endpoint using the "http" node again
  • "code" node to perform calculations on the returned data

When testing the workflow specifically on the "code" node step, the "test step" button executes the code without issue.
However, using the "test workflow" button, the code node timeouts with the following output in the docker logs - (I'm able to report on the cloud environment logs)

2024-12-15 10:17:36 Registered runner "JS Task Runner" (UaR7o06g6XEuPWtygrRob) 
2024-12-15 10:26:52 Converting circular structure to JSON
2024-12-15 10:26:52     --> starting at object with constructor 'TLSSocket'
2024-12-15 10:26:52     |     property '_httpMessage' -> object with constructor 'ClientRequest'
2024-12-15 10:26:52     --- property 'socket' closes the circle
2024-12-15 10:26:52 TypeError: Converting circular structure to JSON
2024-12-15 10:26:52     --> starting at object with constructor 'TLSSocket'
2024-12-15 10:26:52     |     property '_httpMessage' -> object with constructor 'ClientRequest'
2024-12-15 10:26:52     --- property 'socket' closes the circle
2024-12-15 10:26:52     at JSON.stringify (<anonymous>)
2024-12-15 10:26:52     at TaskRunnerWsServer.sendMessage (/usr/local/lib/node_modules/n8n/dist/runners/runner-ws-server.js:67:51)
2024-12-15 10:26:52     at TaskBroker.messageRunner (/usr/local/lib/node_modules/n8n/dist/runners/task-broker.service.js:78:48)
2024-12-15 10:26:52     at TaskBroker.handleRequesterDataResponse (/usr/local/lib/node_modules/n8n/dist/runners/task-broker.service.js:236:20)
2024-12-15 10:26:52     at processTicksAndRejections (node:internal/process/task_queues:95:5)
2024-12-15 10:26:52     at TaskBroker.onRequesterMessage (/usr/local/lib/node_modules/n8n/dist/runners/task-broker.service.js:214:17)
2024-12-15 10:26:52 
2024-12-15 10:27:52 Task runner timed out during task, restarting...

Workarounds

This timeout bug only seems to happen when using the "test workflow" action in non-production mode. I can confirm the following methods of running the workflow do not experience the timeout.

✅ Running via webhook
✅ Runing via subworkflow
✅ Removing the http nodes from the workflow also seems to work

Template.json

{
  "nodes": [
    {
      "parameters": {},
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        -280,
        -160
      ],
      "id": "09b71fd6-1a0f-460b-8ae0-d9f4158c1d0b",
      "name": "When clicking ‘Test workflow’"
    },
    {
      "parameters": {
        "operation": "information"
      },
      "type": "n8n-nodes-base.editImage",
      "typeVersion": 1,
      "position": [
        100,
        -160
      ],
      "id": "33babb35-a642-4d13-982e-8e59f70d74c5",
      "name": "Get Info"
    },
    {
      "parameters": {
        "fieldToSplitOut": "coords",
        "options": {}
      },
      "type": "n8n-nodes-base.splitOut",
      "typeVersion": 1,
      "position": [
        1080,
        -160
      ],
      "id": "8addc95f-b45f-4d77-b09d-ca654921fe8e",
      "name": "Split Out"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "b455afe0-2311-4d3f-8751-269624d76cf1",
              "name": "coords",
              "value": "={{ $json.candidates[0].content.parts[0].text.parseJson() }}",
              "type": "array"
            },
            {
              "id": "92f09465-9a0b-443c-aa72-6d208e4df39c",
              "name": "width",
              "value": "={{ $('Get Info').item.json.size.width }}",
              "type": "string"
            },
            {
              "id": "da98ce2a-4600-46a6-b4cb-159ea515cb50",
              "name": "height",
              "value": "={{ $('Get Info').item.json.size.height }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        640,
        -160
      ],
      "id": "030722dc-de24-40f3-adbb-a40250378c78",
      "name": "Get Variables"
    },
    {
      "parameters": {
        "jsCode": "const { coords, width, height } = $input.first().json;\n\nconst range = 1000;\nconst scaleCoordX = (val) => (val * width) / range;\nconst scaleCoordY = (val) => (val * height) / range;\n  \nconst normalisedOutput = coords\n  .filter(coord => coord.box_2d.length === 4)\n  .map(coord => {\n    return {\n      xmin: coord.box_2d[1] ? scaleCoordX(coord.box_2d[1]) : coord.box_2d[1],\n      xmax: coord.box_2d[3] ? scaleCoordX(coord.box_2d[3]) : coord.box_2d[3],\n      ymin: coord.box_2d[0] ? scaleCoordY(coord.box_2d[0]) : coord.box_2d[0],\n      ymax: coord.box_2d[2] ? scaleCoordY(coord.box_2d[2]) : coord.box_2d[2],\n    }\n  });\n\nreturn {\n  json: {\n    coords: normalisedOutput\n  }\n}"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        860,
        -160
      ],
      "id": "e1877587-4c49-4ba5-9689-5b6022c11978",
      "name": "Scale Normalised Coords"
    },
    {
      "parameters": {
        "url": "https://images.pexels.com/photos/29667271/pexels-photo-29667271/free-photo-of-man-walking-along-historic-european-street.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        -80,
        -160
      ],
      "id": "fa057e73-8ad8-470d-99e7-1d22715c9215",
      "name": "Get Test Image"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash-exp:generateContent",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "googlePalmApi",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{\n{\n  \"contents\": [{\n    \"parts\":[\n        {\"text\": \"Please help me identify all the chairs in this image\"},\n        {\n          \"inline_data\": {\n            \"mime_type\":\"image/jpeg\",\n            \"data\": $json.data\n          }\n        }\n    ]\n  }],\n  \"generationConfig\": {\n    \"response_mime_type\": \"application/json\",\n    \"response_schema\": {\n      \"type\": \"ARRAY\",\n      \"items\": {\n        \"type\": \"OBJECT\",\n        \"properties\": {\n          \"box_2d\": {\"type\":\"ARRAY\", \"items\": { \"type\": \"NUMBER\" } },\n          \"label\": { \"type\": \"STRING\"}\n        }\n      }\n    }\n  }\n}\n}}",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        460,
        -160
      ],
      "id": "5da8c738-a5c9-4900-b3be-4b4589473b24",
      "name": "Gemini 2.0 Object Detection",
      "credentials": {
        "googlePalmApi": {
          "id": "dC4JAL0TiRlyq1TE",
          "name": "Google Gemini(PaLM) Api account"
        }
      }
    },
    {
      "parameters": {
        "operation": "binaryToPropery",
        "options": {}
      },
      "type": "n8n-nodes-base.extractFromFile",
      "typeVersion": 1,
      "position": [
        280,
        -160
      ],
      "id": "f239030b-ec00-4c97-97d7-99822ef8f40d",
      "name": "Extract from File"
    },
    {
      "parameters": {
        "content": "\n\n\n\n\n\n\n\n\n\n\n\n### Timeout Issue\n✅ Works when \"test step\"\n❌ Timeouts when \"test workflow\"",
        "height": 260,
        "width": 260
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        780,
        -180
      ],
      "id": "250c736f-1222-45f6-bc42-c4a6ae9139bc",
      "name": "Sticky Note"
    }
  ],
  "connections": {
    "When clicking ‘Test workflow’": {
      "main": [
        [
          {
            "node": "Get Test Image",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Info": {
      "main": [
        [
          {
            "node": "Extract from File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Variables": {
      "main": [
        [
          {
            "node": "Scale Normalised Coords",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Scale Normalised Coords": {
      "main": [
        [
          {
            "node": "Split Out",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Test Image": {
      "main": [
        [
          {
            "node": "Get Info",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Gemini 2.0 Object Detection": {
      "main": [
        [
          {
            "node": "Get Variables",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract from File": {
      "main": [
        [
          {
            "node": "Gemini 2.0 Object Detection",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {}
}

To Reproduce

  1. Import template.json as attached
  2. Configure credentials as necessary
  3. From the editor UI, hit the "Test Workflow" button at the bottom middle of the screen
  4. The execution should get stuck at the "code" node step and timeout after 60 seconds.
  5. If docker, the logs should report a "Converting circular structure to JSON" warning

Expected behavior

The execution should not timeout.

Operating System

MacOS & n8n Cloud

n8n Version

1.72.1

Node.js Version

20

Database

SQLite (default)

Execution mode

main (default)

@Joffcom
Copy link
Member

Joffcom commented Dec 15, 2024

Hey @jimleuk,

We have created an internal ticket to look into this which we will be tracking as "N8N-7971"

@Joffcom Joffcom added the in linear Issue or PR has been created in Linear for internal review label Dec 15, 2024
@tomi
Copy link
Contributor

tomi commented Dec 18, 2024

@jimleuk thank you for a very detailed bug report! This should be fixed in #12288

@janober
Copy link
Member

janober commented Dec 19, 2024

Fix got released with [email protected]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in linear Issue or PR has been created in Linear for internal review Released
Projects
None yet
Development

No branches or pull requests

4 participants