-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
closing connection throws uncaught error. #1027
Comments
I just tried your example and error was handled by both callbacks:
|
( that's without ssl, connection to port 1234 on which no server is listening ) |
The connection does connect. I can run queries before |
Definitely bizarre. I'll be at a computer soon to take a look. It's possible it's specific to using SSL. In the mean time, what version of this library are you using and what version of Node.js? |
I realized why we seemed (from my perspective) to be talking about different things at first. I did additional testing after writing the first comment, namely trying some queries before calling Anyway here's the versions (both installed today): |
Hmm. So I looked a little and didn't see anything obvious (yet; to me). So I saw you said "with an unhandled ENOTCONN". So when Node.js has an unhandled error, what it does it prints a line of course to the screen, a line with a carrot, and then a full stack trace. Would you be able to paste all that here, please? |
And just to confirm, @CamJN , you're not running Node.js from cygwin environment, correct? |
And no, not under cygwin, I'm on OS X and node was installed via homebrew. |
Cool. I think this stack trace helps a lot :) |
Basically it shows that our call to |
Also, I assume that what you posted above is the only thing in your file? If not, can you try running a file that does nothing but try to connect to MySQL to help rune out the potential of other modules doing something strange? |
In the meantime, I think I may have a lead in that it's SSL-specific. |
Additional data that may help us is if you can set the environment variable |
Yeah that code is all that's in file, I had already been trying to narrow it down to a minimal test case.
running that with
|
As for installing node 0.10.x, I'm willing to do that, but it'll take a while since I didn't go the nvm route to begin with. |
Ok, that's no problem :) That trace gives me a lot to work with, so I may have an answer prior to you getting around to installing v0.10 (hopefully) :) |
I wound up installing node 0.10.36 on a different machine to save myself headaches; and my test case works perfectly. removed 0.10.36 and installed 0.12.0 and the crash happens (again, not the same box, so definitely a 0.12.0 issue). |
Ok. And I think I was able to reproduce on Nde.js 0.12 this weekend. I'm still digging in to see if this is an issue with this module or if I need to file a bug report with Node.js. |
@sidorares would you be wiling to help me with a way to get this to reproduce, mainly so we can determine what to provide to nodejs/node-v0.x-archive#9419 ? |
I'll try to reproduce on osx and ubuntu |
I found an interesting detail, if I don't use ssl, the connection closes cleanly. |
Because creating certs for mysql is a massive pain, I have a script that automates it (if you have openssl.cnf setup correctly, if not you have to answer some questions but the only one that matters is the FQDN of the mysql server):
In my.cnf:
and obviously keep a copy of ca-cert.pem for node-mysql to use. |
I am only new (less than a week) with Node/Socket/MySQL stuff.. but I was experiencing what I believe is the same issue: var app = require("express")();
var http = require("http").Server(app);
var server = require("socket.io")(http);
var mysql = require('mysql');
var conn = mysql.createConnection({
host : 'localhost',
user : 'root',
password : '******',
database : 'databasename'
});
function dataQuery(query){
var result = "";
conn.query(query, function(err, rows, fields) {
if (!err)
result = rows;
else
result = 'error';
});
conn.end();
return result;
} When this function was invoked the first time it would work fine. If it was called a second time then it would fail with the same errors as reported from others. It appeared to me that the createConnection was actually invoking the connection to the database instead of declaring something I could use later. I solved this problem by moving the "var conn =" part of the code inside my dataQuery function as follows: function dataQuery(query){
var result = "";
var conn = mysql.createConnection({
host : 'localhost',
user : 'root',
password : '******',
database : 'databasename'
});
conn.query(query, function(err, rows, fields) {
if (!err)
result = rows;
else
result = 'error';
});
conn.end();
return result;
} This seems to work as I intended.. not sure if this will help others but please let me know if it does. |
@SeanDolan your issue is very different; essentially your issue is that for every one |
i faced similar problem if you set connection variable to null inside the callback function you provide for .end() and set the connection variable by checking something like var cnn=cnn?cnn:mysql.createConnection(params) everything works fine |
Confirming the same issue @CamJN reported - using RHEL 6 x86_64 with Node v0.11.16.
As mentioned, it occurs at Upgrading to Node's (current) long term support release - v4.2.1 - resolves this problem. |
I'm using "mysql": "2.11.1" Got this call stack, after a few hours the connection was active. Is it the same problem? events.js:141 Error: Connection lost: The server closed the connection. Process finished with exit code 1 |
@talbensimhon if you are not using pool you must attach 'error' event listener to connection object, as this is the only way to handle non-command level errors ( like this one - server decided to forcibly close connection ) |
I'm going to close this old issue, as it was a Node.js core bug. Not sure if it was ever fixed, since the issue I opened with Node.js was never resolved. |
Both:
and
Fatal on
connection.end(...)
with an unhandledENOTCONN
which is obviously not being caught by the error handling suggested by the documentation. Either this is a bug in the library or the docs; either way I'd like to know how to actually use this library as right now it defies me.The text was updated successfully, but these errors were encountered: