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

Async loops verification and run problem #486

Closed
victorherraiz opened this issue Aug 18, 2014 · 12 comments
Closed

Async loops verification and run problem #486

victorherraiz opened this issue Aug 18, 2014 · 12 comments

Comments

@victorherraiz
Copy link

I do not know if I am doing something wrong. This is my code:

module.exports = function loadUsers(ids, load, done) {
    var users = [], c = 0;
    ids.forEach(function(id,i){
        load(id, function (v) {
            users[i] = v;
            if(++c === ids.length){
                done(users);
            }
        });
    });
};

It keeps running and it only calls the loop function callback a random number of times before freeze using the 100% cpu time.
I have to stop the node process (ctrl+c) but some "node" process are not kill and remain in the process list.

Software versions:
Node: v0.10.30
[email protected]
os x 10.9.4

Thanks.

@jkbits1
Copy link

jkbits1 commented Aug 18, 2014

That code should work. Are you calling the code as "functional-javascript-workshop verify <file_name>"? You could maybe try "run" instead of "verify", to see if there is a set-up issue.

@victorherraiz
Copy link
Author

I tried run command with same result. It freezes after a random (low) number of callbacks. It seems that there is something blocking the callbacks (CPU 100%), it could be the test code but I did not check it yet.

@jkbits1
Copy link

jkbits1 commented Aug 18, 2014

Your mention of test code may be relevant. Take a look at this issue logged on the workshop itself:
#63

@jkbits1
Copy link

jkbits1 commented Aug 18, 2014

BTW, thanks for providing details about versions and clear info on the software's behaviour. It's very helpful.

@victorherraiz
Copy link
Author

I just test with the same machine, same code, same versions of node and app but different OS (Windows 7).
Same results: It freezes almost every time. It ended only once after several tests.

@jkbits1
Copy link

jkbits1 commented Aug 18, 2014

Thanks for the extra information, it does sound like the same behaviour reported in issue 63 on the workshop itself. That issue now has a link back to this one from my earlier reference, so they can see all your helpful reports.

I have version 0.0.24 of the workshop (and 0.10.25 of Node) and everything works normally. It is possible that installing the earlier version of the workshop will fix things, but it may not.

Your code above works on my set-up. The only difference between your code and the workshop's solution is that the solution returns done(), rather than just calling it. So you have completed the step, but without the nice feeling of the workshop acknowledging that you have.

@victorherraiz
Copy link
Author

WS 0.0.24 + Nodejs 0.10.30 don't work.
WS 0.0.26 + Nodejs 0.10.25 works!!!
Something is not working as expected in the stable release of node.

@jkbits1
Copy link

jkbits1 commented Aug 19, 2014

@ViktorMento thanks very much for testing this out and letting people know. It will be very helpful to those fixing it. 👍

@victorherraiz
Copy link
Author

Node 0.11.13 (latest) works too. It could be a node problem.

@victorherraiz
Copy link
Author

@jkbits1 You are welcome. I am new to Nodejs and I just found "n" module to have several node versions install in a single machine thanks to this problem.

@timoxley
Copy link

Oh wow, so is likely related to the timers bug that was fixed in the latest 0.10.31 release

Code in question:

    setTimeout(function() {
      var match = users.filter(function(user) {return user.id === id})
      if (match.length) fn(match[0])
      else fn(null)
    }, Math.random() * 1000) // non-integer timer

@connor11528
Copy link

Awesome! Good work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants