Skip to content
This repository

Nested requests are blocking #306

reggi opened this Issue · 8 comments

4 participants

Thomas Reggi Max Nowack Mikeal Rogers
Thomas Reggi

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

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 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!

Max Nowack

same problem! :(

Thomas Reggi

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

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.


Thomas Reggi

@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?

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 Rogers

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.

Thomas Reggi

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.

Thomas Reggi reggi closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.