BUG_UnhandledPromiseRejectionWarning: DataCloneError: eventName
See original GitHub issueDescribe 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:
- Created 2 years ago
- Reactions:1
- Comments:7 (4 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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
@pioardi Yes, it is resolved. Thanks for being helpful! And for this awesome library. Looking forward to seeing more features. Cheers!