Changeset: 60d16707a6bf for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=60d16707a6bf
Modified Files:
clients/nodejs/Tests/nodetest.js
clients/nodejs/monetdb/mapiclient.js
clients/nodejs/monetdb/package.json
Branch: default
Log Message:
Node.JS connector: Make sure all callbacks get errors when the connection is
dead or auth fails
diffs (124 lines):
diff --git a/clients/nodejs/Tests/nodetest.js b/clients/nodejs/Tests/nodetest.js
--- a/clients/nodejs/Tests/nodetest.js
+++ b/clients/nodejs/Tests/nodetest.js
@@ -13,7 +13,11 @@ monetdb.connect({dbname:'nonexist', port
assert(err);
});
-monetdb.connect({dbname:dbname, user:'nonexist', port:dbport}, function(err) {
+var failedconn = monetdb.connect({dbname:dbname, user:'nonexist',
port:dbport}, function(err) {
+ assert(err);
+});
+/* try to query on a failed connection, we need this callback */
+failedconn.query('SELECT 1',function(err,res) {
assert(err);
});
diff --git a/clients/nodejs/monetdb/mapiclient.js
b/clients/nodejs/monetdb/mapiclient.js
--- a/clients/nodejs/monetdb/mapiclient.js
+++ b/clients/nodejs/monetdb/mapiclient.js
@@ -28,6 +28,8 @@ function MonetDBConnection(options, conn
this.socket.on('error', function(x) {
if (conncallback != undefined)
conncallback(x.toString());
+ this.state = 'disconnected';
+ cleanup.call(thizz);
});
/* some setup */
this.request('Xreply_size -1', undefined, true);
@@ -44,7 +46,7 @@ function MonetDBConnection(options, conn
thizz.env[l[resp.col.name]] = l[resp.col.value];
});
});
- this.request('SELECT 42', function(x) {
+ this.query('SELECT 42', function(x) {
if (this.conn_callback != undefined)
this.conn_callback(null);
});
@@ -69,19 +71,27 @@ MonetDBConnection.prototype.query = func
}
}
+ if (this.state == 'disconnected') {
+ if (callback != undefined) {
+ callback('Invalid connection');
+ }
+ cleanup.call(this);
+ return;
+ }
+
if (Array.isArray(arguments[1])) {
params = arguments[1];
callback = arguments[2];
raw = arguments[3];
- this.prepare(message, function(err, res) {
+ this.prepare(message, function(err, resp) {
if (err) {
if (callback != undefined) {
callback(err);
}
return;
}
- res.exec(params, function(err, res) {
+ resp.exec(params, function(err, rese) {
if (err) {
if (callback != undefined) {
callback(err);
@@ -89,8 +99,9 @@ MonetDBConnection.prototype.query = func
return;
}
if (callback != undefined) {
- callback(null, res);
+ callback(null, rese);
}
+ resp.release();
});
});
}
@@ -183,6 +194,8 @@ function handle_message(message) {
message = 'Error: ' + message.substring(1,
message.length - 1);
if (this.conn_callback != undefined)
this.conn_callback(message);
+ this.state = 'disconnected';
+ cleanup.call(this);
return;
}
@@ -217,7 +230,6 @@ function handle_message(message) {
next_op.call(this);
}
-
function next_op() {
if (this.queryqueue.length < 1) {
this.alldone = true;
@@ -230,7 +242,16 @@ function next_op() {
var op = this.queryqueue.shift();
send_message.call(this, op.message);
this.read_callback = op.callback;
-}
+}
+
+function cleanup() {
+ while (this.queryqueue.length > 0) {
+ var op = this.queryqueue.shift();
+ if (op.callback != undefined) {
+ op.callback('Invalid connection');
+ }
+ }
+}
function handle_input(data) {
/* we need to read a header obviously */
diff --git a/clients/nodejs/monetdb/package.json
b/clients/nodejs/monetdb/package.json
--- a/clients/nodejs/monetdb/package.json
+++ b/clients/nodejs/monetdb/package.json
@@ -1,6 +1,6 @@
{
"name": "monetdb",
- "version": "0.1.5",
+ "version": "0.1.6",
"description": "Connect MonetDB and node.js",
"main": "mapiclient.js",
"author": "Hannes Mühleisen <[email protected]>",
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list