Proxy sometimes hangs when request is disrupted
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!
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.
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 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; 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.
+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 what's your stack look like?
@noahgrant
proxy-middleware: 0.5.1, gulp-webserver: 0.9.0, node: 0.10.28, gulp: 3.8.11 OSX 10.10.2
+1
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));
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 :-/