node-proxy-middleware icon indicating copy to clipboard operation
node-proxy-middleware copied to clipboard

Proxy sometimes hangs when request is disrupted

Open noahgrant opened this issue 11 years ago • 10 comments

We have a single-page-app with several proxies as we migrate off of rails, and we've found that sometimes, when a request hasn't completed (whether it's a proxied request or not, i think) and we make a new request (either by refreshing the page or, say, clicking another part of the page and triggering a new request), the proxy hangs, and we have to restart our server. On a refresh, we see all locally served files, but requests to a proxied server hang without a response. We're running proxy-middleware within browsersync, all within gulp.

If you have any insights about why this might happen, I'm happy to take a look and give a crack at it, but I figured I should post an issue about it to get some feedback first.

Thanks!

noahgrant avatar Dec 11 '14 01:12 noahgrant

I have not used this module in a while; it's pretty much a community-maintained project at this point. So you'll have to investigate this. Luckily the source is still pretty small so you shouldn't have too hard of a time with it.

andrewrk avatar Dec 11 '14 16:12 andrewrk

I've noticed the same behavior using v0.5.0 and as well on v.0.9.0. Unfortunately I haven't been able yet to figure out the cause; so far it seems to occur at random.

RobbinHabermehl avatar Dec 18 '14 13:12 RobbinHabermehl

@RobbinHabermehl what does the rest of your stack look like? Last week I tried to debug by putting a lot of request/response event hooks in the proxy, but nothing seemed very out of the ordinary when it would hang. I'm thinking it's actually a browsersync issue—are you using browsersync?

noahgrant avatar Dec 21 '14 23:12 noahgrant

@noahgrant; I'm not using browser-sync, nor something similar. Originally version 2.14.x was being used, but I've reproduced the issue with version 3.3.x as well.

RobbinHabermehl avatar Dec 22 '14 14:12 RobbinHabermehl

+1 to this. I'm using a 60-second long-polling interval from the client code to connect-proxy, and then to the backend. When I'm in rapid development and reloading often, these requests seem to get 'stuck' in the queue. No further requests are proxied until the one that's stuck is returned. I have to kill and restart the proxy server

dshefchik avatar Jan 28 '15 21:01 dshefchik

@dshefchik what's your stack look like?

noahgrant avatar Feb 18 '15 16:02 noahgrant

@noahgrant

proxy-middleware: 0.5.1, gulp-webserver: 0.9.0, node: 0.10.28, gulp: 3.8.11 OSX 10.10.2

dshefchik avatar Feb 18 '15 18:02 dshefchik

+1

corentin-gautier avatar Feb 25 '15 11:02 corentin-gautier

I have also run into hanging issues with the proxy until restart - using Ionic Framework and livereload. It would consistently fail after 5 reloads - For my case what is happening is that after 5 tries the http_agent_maxsockets limit is kicking in and further attempts block. Have yet to be able to trackdown the root cause of why the http keep-alive sockets are not getting reused/blocking.

As a quick workaround I turned off keep-alive connection-pooling and no longer have hang ups.

  var opts = url.parse(proxy.proxyUrl);

  //opt out of the pooling
  opts.agent = false;
  app.use('/path/', proxy(opts));

mur-dog avatar Feb 27 '15 04:02 mur-dog

thanks @mur-dog. I'm not sure setting opts.agent to false works for me, because the options headers get set to the request headers, so the request is sent with both agent: false as well as connection: keep-alive (the default connection header). For me, that made the response headers have connection: keep-alive. setting, in your example:

opts = url.parse(proxy.proxyUrl);
opts.headers = {
   connection: 'close'
};

made the response headers give a connection: close. This might hopefully be a workaround, but still doesn't solve the hanging issue :-/

noahgrant avatar Mar 15 '15 19:03 noahgrant