-
-
Notifications
You must be signed in to change notification settings - Fork 73
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
deasync hangs in an asynchronous context #21
Comments
Much more simple example: var deasync = require('deasync');
function async(cb) {
console.log('1');
setTimeout(function() {
console.log('2');
cb(null, 'value');
console.log('3');
}, 0);
}
console.log('A', deasync(async)());
setTimeout(function() {
console.log('B', deasync(async)());
}, 0); I had: $ node test.js
1
2
3
A value
1
^C |
Although haven't found a fix yet, the problem appears only if the nested setTimeout having same timeout parameter. In @maxvyaznikov 's example, changing one of the timeout param away from 0 and 1 (b/c 0 is treated as 1 by Node.js implementation of setTimeout) will avoid hung. This serves as a temporary workaround. |
Functions with Bluebird Promises get stuckI have a bluebird promises implementation of a function that returns the CPS function that hangs as well... https://github.com/marcellodesales/node-pom-parser/blob/master/lib/index.js#L36-L59 If I use the following code, it will just hang: /**
* Setup the temporary pom.xml settings as we still use it.
* TODO: Remove this when we have a registry
*/
Core.prototype._loadPomXmlSettings = function _loadPomXmlSettings() {
this.APP_POM_PATH = this.APP_DIR + "/pom.xml";
if (fs.existsSync(this.APP_POM_PATH)) {
var parser = deasync(pomParser.parse);
console.log(parser);
var resp = parser({filePath: this.APP_POM_PATH});
console.log(resp);
this.pom = resp.pomObject;
}
}; This only prints the following: [Function] When it should print the object below the Functions without it does notI have implemented others functions using the same CPS pattern without bluebird and it works as expected... Those below work find!!! https://github.com/marcellodesales/node-newrelic-api/blob/master/src/deployments.js#L90 https://github.com/marcellodesales/node-newrelic-api/blob/master/src/applications.js#L46 @abbr any suggestion for this one? |
The problem appears to be a Node bug. Have filed issue #25831 and pr #2830 |
@abbr thanks for following up... |
Ran into this issue as well, using node 0.12.7, deasync hangs if called within a .then block of an async function. I noticed a PR has been submitted, @abbr, do you know if this has been merged in yet or if there is any way to port the fix? My specific use case is within a .then block of a sequelize.findAll query (sequelize uses bluebird for promises iirc) |
@abbr has there been any progress on this? |
No. If the issue affects a run time env under your control and there is no workaround, you can compile NodeJS from source with my pr applied (move 1 line of code in |
@sterling , @maxvyaznikov |
@abbr could you please react on the PR #52? I faced that issue in glslify-sync, it is quite acute: setTimeout(function () {
var source = glslify('./file.glsl');
}); Just hangs. Setting timeout to 0, 1 does not help. Please, help. @abbr you have mentioned this for nodejs/node-v0.x-archive#25831, but is there the same issue for node 4.x, 5.x? because I face this in node 5.5.0 |
It's a pity.. Seems that it is thought to be a |
Is there any way to work around this bug? |
I'd say this package isn't really necessary more, now that async functions
exist.
…On Thu, Jan 24, 2019, 7:31 AM Jam Risser ***@***.***> wrote:
Is there any way to work around this bug?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#21 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AH996cZP3D8NQJAhCQK0wR_E4gyPdNIsks5vGaeLgaJpZM4FT0W0>
.
|
Not true. I need it to run some async code on import. |
"deasync" is thread blocking meanwhile async function will split thread in two parts so you need to wrap all code in async/await or into then(). So you might end up with refactoring of all your code if your function you want to deasync is deeply nested. |
I tried to use I also tried to use named pipes to execute timeout in different separated process where is not I also tried to use vm.runInNewContext(code[, sandbox[, options]]) and it also failed because of there no |
i was able to get around this by not using |
Wrapping the code into |
When using a deasynced function in asynchronous code, deasync hangs and never returns.
Notice that when run, the second call to
sync
hangs. I was originally using promises when testing this and derived the previous code from this:I also tried the above example using the Bluebird promise library and ended up with the same results. In the promise example, adding a
console.log
inside theloopWhile
handler shows that it is stuck checkingdone
since the promise chain never completes.The text was updated successfully, but these errors were encountered: