1

Unfortunately I cannot put the code here because despite all kinds of debugging I cannot point to the problem to present the problematic segment of the code. If I try to load a HTML which in turn has other requests (js,css,png, etc.), it loads all except one... The server/browser hangs for some time and then after about a minute or so does actually load! If I try to test the server with individual manual requests of these very URLs in the HTML file, it works fine.

While tying to load the HTML file, Chrome Network tab shows "pending..." of one request or sometimes two. But ultimately all the URLs requested are served. Thats what bugs me...

I tried to set http.globalAgent.maxSockets to 100 as suggested here as the HTML file would make more than 8 requests for the different js, css, etc. This did not help either.

I have reached a deadend. Any help would be appreciated.

Community
  • 1
  • 1
Sunny
  • 9,245
  • 10
  • 49
  • 79
  • 2
    My first guess would be that you have some synchronous code going on, or a loop without a failsafe. Either that or your application is being influenced by something else on the machine, have you tried running it on another computer or server to see if the issue persists? – Wouter Nov 12 '15 at 14:55
  • 1
    `http.globalAgent.maxSockets` is only useful for HTTP clients (and on more recent Node versions there isn't a limit anymore). – robertklep Nov 12 '15 at 15:31
  • @Wouter, Yes, I do have a couple of synchronous I/O calls but they are not the reason. They get completed.. I have traced that. I do have a few asynchronous MySQL db calls too which have callbacks which are completed. This machine is dedicated to just this development and just to me. What are the possible bottlenecks which ultimately timeout? There is not much processing that is holding up anything. In fact, I have commented out the dynamic HTML generation part to get to the root of the problem. – Sunny Nov 12 '15 at 15:42
  • 1
    @Samir the best way to find out what causes it is to profile your app. Or, the easier way (what I tend to do), would be to log every major step in your app using `console.log` with a timestamp, a descriptive message what the app is doing, and perhaps a printout of some variables. That way you can trace what it's doing and where it hangs. Then you go to the part where it hangs, and log even more detailed to find out what exactly is causing the problem. Once you've identified the culprit you can post some code here and we can all take a look and help you fix it. – Wouter Nov 12 '15 at 16:45
  • @Wouter, That is exactly what i have been doing for a few hours now... It would have been easier if there was a failure right away... the fact that it stalls and then sends the response is what is frustrating my efforts. As suggested, I will try to time various sections and see which part is holding it up... – Sunny Nov 12 '15 at 18:30
  • @Wouter. Found the problem... Followed your advice. Your suggestion helped. If you post it as an answer I will certainly accept it. Did a timestamp in every function, middleware or otherwise, at the beginning and end for each resource requested. A Mysql connection termination problem hanged one function randomly... The timestamp pairs was missing for this function when the response was hanging... Once I had narrowed the problem, took steps to ensure that MySQL connections were terminated promptly. All's well for now. Debugging asynchronous code is a whole different beast... – Sunny Nov 13 '15 at 13:12

0 Answers0