Skip to content

Experiencing Error: connect EMFILE #585

Closed
@simoami

Description

@simoami

I'm testing a proxy on a separate java app. The app has about 280 static resources (js, css and images) in non-production mode.

After a number of requests on a single page load, I start getting the EMFILE error, which typically indicates a resource leak, more precisely "Too many open file descriptors".

Attached my code below.

  1. Would provide any pointers on what could be the problem?
  2. Do you have any recommendations on handling request and response objects to avoid leaks?
  3. Not sure if this is related, but can you explain why proxyReq.end() is commented out? Is it intentional?

code contains only the relevant parts:

init: function(proxyOptions) {
    ...
    this.proxy = new httpProxy.createProxyServer(proxyOptions);
    this.proxy.on('proxyRes', this.handleProxyResponse.bind(this));

    this.server = http.createServer(this.handleWebRequest.bind(this));
    this.server.listen(this.port);
},
handleWebRequest: function (req, res) {
    this.emit('request', req, res);
    this.proxy.web(req, res, this.proxyOptions);
},
handleProxyResponse: function (res) {
        var req = res.req;
        if (this.isHttpRedirect(res)) {
            var reqUrl = (req.connection.encrypted ? 'https://' : 'http://') + req.getHeader('host'),
                // need to use url.resolve() in case location is a relative URL
                location = url.resolve(reqUrl, res.headers.location), //res.getHeader('location');
                locationObj = url.parse(location);
            this.rewriteLocation(locationObj, res);
        }
        this.emit('proxy-response', res);
},

Thanks,

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions