question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

BUG_UnhandledPromiseRejectionWarning: DataCloneError: eventName

See original GitHub issue

Describe the bug A clear and concise description of what the bug is. I tried to create Fixed and Dynamic ThreadPools as follows and try to pass the mongo db instance to the worker. It throws an error as follows:

api      |     Merkle Root: 0x29711e9454dc2c1d629c0cdc0b0924d762db96cd86b3702c4af32b71469e2fa8
api      | (node:21) UnhandledPromiseRejectionWarning: DataCloneError: eventName => {
api      |     if (DEPRECATED_UNIFIED_EVENTS.has(eventName)) {
api      |       emitDeprecationWarning(
api      |         `The \...<omitted>... } could not be cloned.
api      |     at Worker.postMessage (internal/worker.js:223:23)
api      |     at g.sendToWorker (/usr/api/node_modules/poolifier/lib/index.js:1:5850)
api      |     at g.execute (/usr/api/node_modules/poolifier/lib/index.js:1:3871)
api      |     at sendCredentialIssuedEmail (/usr/api/src/email/sendCredentialIssuedEmail.js:85:14)
api      |     at Server.issueAndPublishCertificates (/usr/api/src/routes/issuer.js:282:5)
api      |     at processTicksAndRejections (internal/process/task_queues.js:93:5)
api      | (node:21) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
api      | (node:21) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Using Cluster Fixed Pool gave following issue :

api      |     Merkle Root: 0x211155733b5f5bd5e88f99c833fb0c95917aa6fd7d4bb51cb5e2b443acb05590
api      | (node:19) UnhandledPromiseRejectionWarning: TypeError: Converting circular structure to JSON
api      |     --> starting at object with constructor 'NativeTopology'
api      |     |     property 's' -> object with constructor 'Object'
api      |     |     property 'sessionPool' -> object with constructor 'ServerSessionPool'
api      |     --- property 'topology' closes the circle
api      |     at JSON.stringify (<anonymous>)
api      |     at ChildProcess.target._send (internal/child_process.js:778:25)
api      |     at ChildProcess.target.send (internal/child_process.js:676:19)
api      |     at Worker.send (internal/cluster/worker.js:43:28)
api      |     at y.sendToWorker (/usr/api/node_modules/poolifier/lib/index.js:1:5413)
api      |     at y.execute (/usr/api/node_modules/poolifier/lib/index.js:1:3871)
api      |     at sendCredentialIssuedEmail (/usr/api/src/email/sendCredentialIssuedEmail.js:85:14)
api      |     at Server.issueAndPublishCertificates (/usr/api/src/routes/issuer.js:282:5)
api      |     at processTicksAndRejections (internal/process/task_queues.js:93:5)
api      | (node:19) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
api      | (node:19) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Steps to reproduce the behavior

    const workerScript = path.join(__dirname, './yourWorker.js');
    const pool = new FixedThreadPool(15,
        workerScript,
        { errorHandler: (e) => console.error(e), onlineHandler: () => console.log('worker is online') })

    let resolved = 0
    const start = Date.now()
    const certsCount = _.size(issuedCerts);
    for (const issuedCert of issuedCerts) {
        pool
            .execute({
                cert: issuedCert,
                db,
            })
            .then(res => {
                resolved++
                if (resolved === certsCount) {
                    return console.log('Time take is ' + (Date.now() - start))
                }
                return null
            })
            .catch(err => console.error(err));
    }

Info

Tool Version
Poolifier v2.0.1
Node v node:12.13.1-stretch - Docker
OS linux - Debian - Docker

Additional context

Worker is an async task processor Tried both Fixed and Dynamic Pools

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
pioardicommented, Apr 10, 2021

Hi @chamikabm nice to meet you and thanks to use poolifier. As per node.js documentation you can only pass serializable data from the main process to the worker threads. I think this is the main issue here, you could try to have one mongodb client instance per thread ,but my suggestion is to avoid I/O operations ( like write/read from a database ) into worker threads since they are particurlarlly useful for CPU tasks. You can try to split your tasks in two/three and only do CPU stuff in worker threads, or in alternative try to instantiate the mongodb client into the worker thread directly.

Hope this helps

1reaction
chamikabmcommented, Apr 11, 2021

@pioardi Yes, it is resolved. Thanks for being helpful! And for this awesome library. Looking forward to seeing more features. Cheers!

Read more comments on GitHub >

github_iconTop Results From Across the Web

nodejs - DataCloneError: function () { [native code] } could not ...
I'm trying to spawn threads (using the new Nodejs module 'worker_threads') and pass to each of them a complex object which is the...
Read more >
DataCloneError: The object can not be cloned. #606 - GitHub
I have used this awesome library in react. Getting this error Unhandled Promise Rejection: DataCloneError: The object can not be cloned.
Read more >
postMessage throws DataCloneError: The object could not be ...
Actual results: An error is returned : DataCloneError: The object could not be cloned. Expected results: The object should have been transferred without...
Read more >
Viewing online file analysis results for 'client.exe'
client.exe. This report is generated from a file or URL submitted to this webservice on May 1st 2020 08:27:59 (UTC) Guest System: Windows...
Read more >
nodejs - DataCloneError: function () { [native ...anycodings
nodejs - DataCloneError: function () { [native code] } could not be cloned I'm trying to spawn threads (using the new ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found