Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: EMFILE, Too many open files #43

Closed
CrabDude opened this issue Nov 22, 2010 · 5 comments
Closed

Error: EMFILE, Too many open files #43

CrabDude opened this issue Nov 22, 2010 · 5 comments

Comments

@CrabDude
Copy link

Connections often became stale and so as a result I was recreating / restarting connections before timeout to ensure freshness, over time the following error occurred:

20 Nov 20:15:01 - Error: EMFILE, Too many open files
at net:907:19
at Object.lookup (dns:138:5)
at Stream.connect (net:902:9)
at connect (/usr/local/lib/node/.npm/mysql/0.8.0/package/lib/mysql/client.js:79:16)
at Client._prequeue (/usr/local/lib/node/.npm/mysql/0.8.0/package/lib/mysql/client.js:245:3)
at Stream. (/usr/local/lib/node/.npm/mysql/0.8.0/package/lib/mysql/client.js:77:14)
at Stream.emit (events:27:15)
at IOWatcher.callback (net:471:53)
at node.js:772:9

Here is the code that was resetting the connection:

var sphinx = new Client(),
    client = new Client(),
    mysqlReset = 300000;

sphinx.user = 'XXXXX';
sphinx.port = '9306';
sphinx.host = '127.0.0.1';
sphinx.connect();

client.user = 'xxxxxxx';
client.password = 'XXXXXX;
client.database = 'XXXXXX';
client.host = '127.0.0.1';
client.connect();

setInterval(function() {
    resetMysql(client,function(newClient) {
        client = newClient;
    });
    resetMysql(sphinx,function(newClient) {
        sphinx = newClient;
    });
}, mysqlReset);

function resetMysql(old, cb) {
    var temp = new Client();
    for (var i in old) {
        if (old.hasOwnProperty(i) && typeof old[i] != 'undefined' && old[i] !== null && old[i].constructor != Function) {
            temp[i] = old[i];   
        }
    };
    temp.connect(function() {
        cb(temp);
        old.end();
    });
}
@Sannis
Copy link

Sannis commented Nov 24, 2010

I fix similar error with replacing conn.end() by conn.destroy(), but I think this isn't good way. Also I try to use reverse callback order, but it doesn't matter.
old.end(function () {
temp.connect(function (err) {
cb(temp);
});
});

I specially disable DNS lookups in MySQL server to increase performance and switch to IP when connect to DB with node-mysql (for benchmarking node MySQL bindings). So it is interesting for me, is it a bug in node-mysql or in Node itself.

@CrabDude
Copy link
Author

I know it used to be a bug in Node itself, but it appears to have been resolved, though maybe this is proving to be an edge case.

@felixge
Copy link
Collaborator

felixge commented Nov 25, 2010

CrabDude: Are you sure that your mysql connections are going stale? If that's the case then it is a bug. I've explicitly added support for automatic re-connection in these scenarios.

@CrabDude
Copy link
Author

@felixge: I never verified, and unfortunately I am no longer on the project. It was something that would come up eventually every time which I resolved by merely letting the process die and be restarted by multi-node. Hopefully it was just something on my end. ;)

@felixge
Copy link
Collaborator

felixge commented Dec 17, 2010

Alright, I'll close this for now until I have a way to reproduce the problem.

dveeden pushed a commit to dveeden/mysql that referenced this issue Jan 31, 2023
add tests for charset parameter on live connection
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants