hapijs / h2o2

Proxy handler for hapi.js
Other
165 stars 66 forks source link

onResponse proxy is not closing connections? #105

Closed datvong-wm closed 4 years ago

datvong-wm commented 5 years ago

Using Hapi@17.8.4, h2o2@8.1.2. Create a simple proxy below, using onResponse.

server.route({
      method: "GET",
      path: "/test",
      handler: async (req, h) => {
        return h.proxy({
          mapUri: async(req) => {
            const uri = url.format("https://www.google.com");
            return {uri};
          },
          onResponse: (err, res, req, h) => {
            return h.response({ok:true});
          }
        })
      }
    });

When I hit my /test route, it keeps the proxy connects alive. When I look at the open file handles, it shows the connections in CLOSE_WAIT state.
And looking at the memory profiler, the memory used by the process balloons with every request.

Screen Shot 2019-09-26 at 10 17 42 AM

hueniverse commented 5 years ago

It's an override and it is your responsibility to clean things up since the plugin doesn't know what you are doing with the streams.

datvong-wm commented 5 years ago

For anyone getting this issue. Fix is to close res().

          onResponse: (err, res, req, h) => {
            res.destroy();
            return h.response({ok:true});
          }