Skip to content

Error: connect EMFILE and node-http-proxy #567

Closed
@stockholmux

Description

@stockholmux

I'm trying to reverse proxy three localhost ports to a single localhost port. I keep getting the error:

{ [Error: connect EMFILE] code: 'EMFILE', errno: 'EMFILE', syscall: 'connect' }

After about ~100 serves. I can connect directly to the servers without issue for thousands of serves and nginx works well using the same reverse proxy.

Here is my code:

var http = require('http'),
    httpProxy = require('http-proxy');

var proxy = httpProxy.createProxyServer({});

var server = require('http').createServer(function(req, res) {
    if (req.url.match(/^(\/api\/search|\/api\/suggest)/g)) {
        proxy.web(req, res, { target: 'http://127.0.0.1:2700' });
    } else if (req.url.match(/^\/pages\//g)){
        proxy.web(req, res, { target: 'http://127.0.0.1:3100' });
    } else {
        proxy.web(req, res, { target: 'http://127.0.0.1:3000' });
    }
});

server.listen(9999);

I have also asked about the same issue in this Stackoverflow question. EMFILE issues seem to be around issues with maxfiles, but it given that I can run everything without the proxy with no issues, it seems like node-http-proxy not closing something?

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