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

fix(sandbox): serialize sandboxed job error #2813

Closed
wants to merge 1 commit into from

Conversation

LEI
Copy link

@LEI LEI commented Oct 9, 2024

This change preserves the original error when throwing from a sandboxed job with a circular reference or I think a function in the object.

The TypeError is reproducible with worker threads off and a simple circular reference:

Worker failed TypeError: Converting circular structure to JSON
    --> starting at object with constructor 'Object'
    --- property 'ref' closes the circle
    at stringify (<anonymous>)
    at writeChannelMessage (node:internal/child_process/serialization:159:20)
    at target._send (node:internal/child_process:851:17)
    at target.send (node:internal/child_process:751:19)
    at ./node_modules/bullmq/dist/cjs/utils.js:134:18
    at new Promise (<anonymous>)
    at asyncSend (./node_modules/bullmq/dist/cjs/utils.js:132:12)
    at childSend (./node_modules/bullmq/dist/cjs/utils.js:152:56)
    at ChildProcessor.send (./node_modules/bullmq/dist/cjs/classes/main.js:9:57)
    at ./node_modules/bullmq/dist/cjs/classes/child-processor.js:77:28

The DataCloneError occurs with axios errors and useWorkerThreads: true, see this branch:

Worker failed DataCloneError: function transformRequest(data, headers) {
    const contentType = headers.getContentType() || '';
    const ha...<omitted>... } could not be cloned.
    at new DOMException (node:internal/per_context/domexception:53:5)
    at ChildProcessor.send (./node_modules/bullmq/dist/cjs/classes/main-worker.js:9:69)
    at ./node_modules/bullmq/dist/cjs/classes/child-processor.js:77:28
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Initially attempted to check the value type ignoring "function" and serializing only "object", but using the stringify/parse method on the whole object seems more consistent and fixed all cases.

Avoid a TypeError/DataCloneError when throwing from a sandboxed job with
a circular reference or a function
github-actions bot pushed a commit that referenced this pull request Oct 12, 2024
## [5.19.1](v5.19.0...v5.19.1) (2024-10-12)

### Bug Fixes

* **sandbox:** fix serialization of error with circular references are present ([#2815](#2815)) fix [#2813](#2813) ([a384d92](a384d92))
@LEI LEI deleted the sandbox-error branch October 13, 2024 08:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants