nxtedition/node-http2-proxy

unknown difference between 4.2.15 and 5.0.13

risacher opened this issue · 7 comments

My reverse proxy works a charm with 4.2.15, but not at all with 5.0.31. After staring deeply at it, I'm stumped. The code in question (from https://github.com/risacher/yxorp-edon/blob/master/src/yxorp-http2.js) looks like this:

const listener = function (req, res) {
  
  var target = route(req);
  
  if (null == target) {
    res.writeHead(502);
    res.end("502 Bad Gateway\n\n" + "MATCHLESS request: "+ req.headers.host+req.url);
  } else {
    proxy.web(req, res,
              { onReq: (req, options) => {
                  
                  options.headers['x-forwarded-for'] = req.socket.remoteAddress;
                  options.headers['x-forwarded-port'] = req.socket.localPort;
                  options.headers['x-forwarded-proto'] = req.socket.encrypted ? 'https' : 'http';
                  options.headers['x-forwarded-host'] = req.headers['host'];
                  options.headers['host'] = req.headers['host'];
                  options.rejectUnauthorized = false;
                  options.trackRedirects = true;
                  options.host = target.host;                  
                  options.hostname = target.hostname;
                  options.port = target.port;
                  options.path = target.path;
                  options.protocol = target.protocol+':';
                  
                  var r = (target.protocol === 'http')?
                      http.request(options)
                      : https.request(options);
                  return r;
                },
              }, defaultWebHandler );
  }
};

After instrumenting http2-proxy to death, I can see that deferToConnect() is called, but the 'socket' event on the proxyReq never fires - I don't understand why. As a result, the proxyReq is never issued, and the clientReq eventually times out. Can anyone help?

ronag commented

If you could provide a full sample reproducing the issue I'd be more than happy to take a look.

ronag commented

Hm, did you try 5.0.32? I think we've recently fixed something related.

5.0.32 does not fix, alas.

simplified demo of bug: https://github.com/risacher/http2-proxy-bug-demo

ronag commented

@risacher: I'm sorry but I can't run that. If you can create a minimal & runnable repo I'll gladly look into it.

@ronag Okay, sorry. Updated it so demo uses self-signed certs (included) and no privileged ports. Should run out-of-the-box now.

ronag commented

Thanks! Try 5.0.34

Fixed for both the test case and my actual reverse proxy. Thanks!