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

undefined is not a function #676

Closed
Jpunt opened this issue Jun 10, 2015 · 5 comments
Closed

undefined is not a function #676

Jpunt opened this issue Jun 10, 2015 · 5 comments

Comments

@Jpunt
Copy link

Jpunt commented Jun 10, 2015

In our logging I've found an exception that I can't find the reason for. It's a classical helpful "undefined is not a function" and it seems to have something to do with Superagent:

Message: undefined is not a function
    Request.Request.callback in /app/node_modules/superagent/lib/node/index.js:781
    ClientRequest.[anonymous] in /app/node_modules/superagent/lib/node/index.js:736
    ClientRequest.ClientRequest.emit in events.js:107
    TLSSocket.TLSSocket.socketOnEnd in _http_client.js:300
    TLSSocket.TLSSocket.emit in events.js:129
    unknown.[anonymous] in _stream_readable.js:908
    process.process._tickCallback in node.js:355

We're making several superagent-calls to several different endpoints and I don't know at what URL or under what conditions this exception is thrown.

Looking at the code, it seems to have something to do with a missing callback:

https://github.com/visionmedia/superagent/blob/master/lib/node/index.js#L781

//...
var fn = this._callback;
//...
if (err) {
  return fn(err, res); // #781
}
//...

https://github.com/visionmedia/superagent/blob/master/lib/node/index.js#L736

//...
req.on('error', function(err){
    // flag abortion here for out timeouts
    // because node will emit a faux-error "socket hang up"
    // when request is aborted before a connection is made
    if (self._aborted) return;
    self.callback(err); // #736
  });
//...

We don't have any calls without a callback. Do we have to handle exceptions like timeouts in a different/manual manner maybe?

@defunctzombie
Copy link
Contributor

You shouldn't need to. Have you been able to track this down anymore?

@Jpunt
Copy link
Author

Jpunt commented Aug 6, 2015

No, I can't for the life of me figure out why this is happening. The exception is still thrown a lot and I'll try to make time to take another look at it. Any hints of what direction I should be looking?

@GDreyV
Copy link

GDreyV commented Aug 11, 2015

Hi, not sure if it's the same issue but I managed to reproduce this exception. I just created request and didn't call end(). I thought that request just shouldn't be issued but it causes exception instead. The point was that I was writing the test and I didn't want to send real HTTP request. I thought not calling end() should do the trick.
So I have to call abort() and now tests hangs for a moment. It looks like request is really sent and aborting takes some time.

@defunctzombie
Copy link
Contributor

@GDreyV This is related/duplicate of #714. See my explanation there on why this happens.

@Jpunt
Copy link
Author

Jpunt commented Aug 12, 2015

Thanks, I'll take a look at that one ASAP.

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

No branches or pull requests

3 participants