Nested requests are blocking #306

Closed
reggi opened this Issue Aug 23, 2012 · 8 comments

Comments

Projects
None yet
4 participants
@reggi

reggi commented Aug 23, 2012

I am relatively new to nodejs. I've been recently pooling all of the collective knowledge i've gathered through the past couple of months into an project. I believe I've ran into my first "blocking" issue in nodejs.

I have a page that loads two request() calls they are async and nested accordingly. The innermost one uses data from the innermost to redirect the user.

  request(parameters),function(error, response, data){
      //the first request passes a token  
      request(newParamters),function(error, response, data){
          //the second request passes a url
          res.redirect(data.info.url);
      });
  });

The error is that when I open this up in many browser tabs it ends up breaking after the first couple then the server says data.info.url is undefined.

My question to you is: Should I only be performing one request at a time? I could save the token from the first request() and redirect the user to the second request() would this help? I've been very conscience about async and not blocking and I'm shocked that this is happening. Any feedback would be great!

@maxnowack

This comment has been minimized.

Show comment Hide comment
@maxnowack

maxnowack Aug 24, 2012

same problem! :(

same problem! :(

@reggi

This comment has been minimized.

Show comment Hide comment
@reggi

reggi Aug 25, 2012

@maxnowack What gives? Is it a flaw with the module?

reggi commented Aug 25, 2012

@maxnowack What gives? Is it a flaw with the module?

@Marak

This comment has been minimized.

Show comment Hide comment
@Marak

Marak Aug 25, 2012

I'm fairly certain the issue isn't with the request module.

Could either of you post a minimal reproducible example ( a gist that can be run as-is with no external deps ) ?

If you can provide that, I'd be glad to run it, and help try and fix it.

Thanks!

Marak commented Aug 25, 2012

I'm fairly certain the issue isn't with the request module.

Could either of you post a minimal reproducible example ( a gist that can be run as-is with no external deps ) ?

If you can provide that, I'd be glad to run it, and help try and fix it.

Thanks!

@reggi

This comment has been minimized.

Show comment Hide comment
@reggi

reggi Aug 25, 2012

@Marak I put this together and it seems to be working great. I guess I need to get deep into fixing my own code. @maxnowack how simular is your issue?

reggi commented Aug 25, 2012

@Marak I put this together and it seems to be working great. I guess I need to get deep into fixing my own code. @maxnowack how simular is your issue?

@Marak

This comment has been minimized.

Show comment Hide comment
@Marak

Marak Aug 25, 2012

There's a few common pitfalls that might get you into situations like this.

  • not catching all errors
  • browsers limit amount of concurrent requests over all tabs and windows
  • favicon file requests are unexpected and cause errors
  • async forEach scope failure

Marak commented Aug 25, 2012

There's a few common pitfalls that might get you into situations like this.

  • not catching all errors
  • browsers limit amount of concurrent requests over all tabs and windows
  • favicon file requests are unexpected and cause errors
  • async forEach scope failure
@mikeal

This comment has been minimized.

Show comment Hide comment
@mikeal

mikeal Aug 29, 2012

Owner

your issue probably exists outside the closure you've included in this example, most likely where you define parameters and newParameters. if you can send more of the example we can probably help you, although i'm certain this is not an issue in request.

Owner

mikeal commented Aug 29, 2012

your issue probably exists outside the closure you've included in this example, most likely where you define parameters and newParameters. if you can send more of the example we can probably help you, although i'm certain this is not an issue in request.

@reggi

This comment has been minimized.

Show comment Hide comment
@reggi

reggi Aug 30, 2012

This was totally my fault. I was pinging for a request token multiple times succession rather than storing it and it wasn't being returned in the first request.

reggi commented Aug 30, 2012

This was totally my fault. I was pinging for a request token multiple times succession rather than storing it and it wasn't being returned in the first request.

@reggi reggi closed this Aug 30, 2012

@Marak

This comment has been minimized.

Show comment Hide comment
@Marak

Marak Aug 30, 2012

Marak commented Aug 30, 2012

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