sqlanywhere / node-sqlanywhere

SAP SQL Anywhere Database Client for Node

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

conn.disconnect() crashes Nodejs

LexDias opened this issue · comments

We're working on a Nodejs app accessing a SQL Anywhere 16 Database.

We have an HTML page that performs two simultaneous requests to our Nodejs app. When the first one disconnects, Nodejs crashes.

These are the listeners to both requests:

router.get('/req1', function(req, res, next) {
    var conn = sqlanywhere.createConnection();
    conn.connect({...}, function() {
        conn.exec('SELECT TOP 10 * FROM myTable', [], function (err, result) {
            if (err) throw err;
            res.send(result);
            conn.disconnect();
        })
    });
});

router.get('/req2', function(req, res, next) {
    var conn = sqlanywhere.createConnection();
    conn.connect({...}, function() {
        conn.exec('SELECT count(*) AS cont FROM myTable', [], function (err, result) {
            if (err) throw err;
            res.send(result);
            conn.disconnect();
        })
    });
});

This is the Nodejs crash message:

npm ERR! Windows_NT 6.1.7601
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "start"
npm ERR! node v4.4.6
npm ERR! npm  v2.15.5
npm ERR! code ELIFECYCLE
npm ERR! admin@0.0.0 start: `node ./bin/www`
npm ERR! Exit status 3221225477
npm ERR!
npm ERR! Failed at the admin@0.0.0 start script 'node ./bin/www'.
npm ERR! This is most likely a problem with the admin package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node ./bin/www
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs admin
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!
npm ERR!     npm owner ls admin
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     C:\node-projects\emb-admin\npm-debug.log

When we remove these 'conn.disconnect();' lines, everything works fine. However, all connections to the database remain open.

Any suggestions?

I have confirmed that this is a bug in the driver which I am in the process of fixing. In the meantime, you can get around the problem by preparing a statement and executing that rather than executing it directly through the connection. Rather than:

conn.connect({...}, function() {
   conn.exec('SELECT TOP 10 * FROM myTable', [], function (err, result) {
      ...
      conn.disconnect();
      ...

do this:

conn.connect({...}, function() {
   var stmt = conn.prepare('SELECT TOP 10 * FROM myTable' );
   stmt.exec( [], function (err, result) {
      ...
      stmt.drop();
      conn.disconnect();
      ...

Thank you very much for your help! We've tested these mods and they worked fine!

Version 1.0.11 (just published) should fix this problem.

Thank you very much! Just updated it, rolled back those mods and everything look good.

I've downloaded v.1.0.12 and the initial problem returned. Any ideas?