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

Cannot read property '__ConsumeGenerator__' of null #518

Closed
pavel opened this issue Aug 5, 2016 · 10 comments
Closed

Cannot read property '__ConsumeGenerator__' of null #518

pavel opened this issue Aug 5, 2016 · 10 comments

Comments

@pavel
Copy link

pavel commented Aug 5, 2016

Environment

Highland: 3.0.0-beta.2
Node: v6.3.1
OS: Linux

Example (CoffeeScript)

Stream = require "highland"

fn = ->
    Stream Promise.resolve([])
        .map (data) ->
            console.log "map", data
            Stream Promise.resolve([])
        .parallel 1
        .consume (err, data, push, next) ->
            push null, Stream.nil

Stream([
    Stream([["data"]])
    fn().collect()
])
    .parallel 2
    .tap (data) -> console.log "tap", data
    .collect()
    .each (data) -> console.log "each", data

Error

/home/user/highland-bug/node_modules/highland/lib/index.js:1280
        if (gen.__ConsumeGenerator__) {
               ^

TypeError: Cannot read property '__ConsumeGenerator__' of null
  at Stream._runGenerator (/home/user/highland-bug/node_modules/highland/lib/index.js:1280:16)
  at Immediate.<anonymous> (/home/user/highland-bug/node_modules/highland/lib/index.js:791:26)
  at runCallback (timers.js:570:20)
  at tryOnImmediate (timers.js:550:5)
  at processImmediate [as _immediateCallback] (timers.js:529:5)

Does only happen when Promise are in use.
Substituting Promise.resolve([]) to [[]] works without error.

@pavel
Copy link
Author

pavel commented Aug 5, 2016

Replacing .parallel 1 with .series() eliminates the error.

@vqvu
Copy link
Collaborator

vqvu commented Aug 6, 2016

I think this is an easy fix. The call to _runGenerator here needs to check if the generator still exists. It could have been destroyed by downstream.

I'm away from my computer for the new week or so though, so I won't be able to get around to this until then.

@pavel
Copy link
Author

pavel commented Aug 6, 2016

@vqvu You mean this check?

@vqvu
Copy link
Collaborator

vqvu commented Aug 6, 2016

Yeah.

@svozza
Copy link
Collaborator

svozza commented Aug 6, 2016

I'm having trouble reproducing this, I translated it into ES5 here to create a failing test case but it passes for me. Is there something wrong with my code here?

var fn = function() {
        return _(Promise.resolve([]))
            .map(function (x) {
                return _(Promise.resolve([]));
            })
            .parallel(1)
            .consume(function (err, data, push, next) {
                push(null, _.nil);
            });
    };

    _([_([['data']]),
    fn().collect()])
        .parallel(2)
        .collect()
        .each(function(xs) {
            console.log(xs);
        });

@vqvu
Copy link
Collaborator

vqvu commented Aug 6, 2016

Here's a more explicit test case.

var _ = require("highland");

// Code path is this:
// - push(...) causes s.destroy() to be queued.
// - next2 is queued.
// - next1 is executed, which queues _runGenerator
// - destroy() runs and clears the _generator.
// - next2 runs and sets the _generator_requested flag.
// - _runGenerator runs and is allowed to be executed because _generator_requested
//   was set.
var s = _(function (push, next) {
    setTimeout(function () {
        push(new Error("error"));
        _.setImmediate(next); // next2
        next(); // next1
    }, 0);
});

s.pull(function (err, x) {
    // This pull is required to un-pause the stream.
    s.pull(function () {
        // Ignore.
    });

    _.setImmediate(function () {
        s.destroy();
    });
});

I thought about this more and I think the correct fix is to check for _explicitly_destroyed at the start of _next_fn and immediately return if it's true. I believe this also needs to be done in _writeOutgoing.

@svozza
Copy link
Collaborator

svozza commented Aug 6, 2016

Ah yes, this causes failures for me now too. I'll raise a PR in the morning.

@vqvu
Copy link
Collaborator

vqvu commented Aug 7, 2016

@pavel, since we're not testing against the test case that you provided, can you verify that #521 fixes the issue for you?

@pavel
Copy link
Author

pavel commented Aug 8, 2016

@vqvu I've verified, and the fix does resolve the problem.

@vqvu
Copy link
Collaborator

vqvu commented Aug 9, 2016

#521 was merged, so I will close this.

@vqvu vqvu closed this as completed Aug 9, 2016
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

3 participants