Node-mssql: Exception on ConnectionPool release

Created on 5 May 2017  路  18Comments  路  Source: tediousjs/node-mssql

I'm getting a uncaught exception since I upgraded to v4.
I couldn鈥檛 pinpoint from the stack trace (below) when/where exactly it's happening.

Except for the v3 to v4 migration, I didn鈥檛 change anything else in my code.

TypeError: Cannot read property 'release' of null
    at ConnectionPool.release (/app/node_modules/mssql/lib/base.js:199:14)
    at Request.tds.Request.err [as userCallback] (/app/node_modules/mssql/lib/tedious.js:608:25)
    at Request._this.callback (/app/node_modules/tedious/lib/request.js:47:27)
    at Connection.message (/app/node_modules/tedious/lib/connection.js:1401:27)
    at Connection.dispatchEvent (/app/node_modules/tedious/lib/connection.js:687:45)
    at MessageIO.<anonymous> (/app/node_modules/tedious/lib/connection.js:602:18)
    at emitNone (events.js:86:13)
    at MessageIO.emit (events.js:186:7)
    at ReadablePacketStream.<anonymous> (/app/node_modules/tedious/lib/message-io.js:102:16)
    at emitOne (events.js:96:13)
    at ReadablePacketStream.emit (events.js:189:7)

Hope you'll be able to help, thanks!

Most helpful comment

I am having the same issue.

TypeError: Cannot read property 'release' of null
    at ConnectionPool.release (/var/app/current/node_modules/mssql/lib/base.js:199:14)
    at Request.tds.Request.err [as userCallback] (/var/app/current/node_modules/mssql/lib/tedious.js:608:25)
    at Request._this.callback (/var/app/current/node_modules/tedious/lib/request.js:47:27)
    at Connection.message (/var/app/current/node_modules/tedious/lib/connection.js:1401:27)
    at Connection.dispatchEvent (/var/app/current/node_modules/tedious/lib/connection.js:687:45)
    at MessageIO.<anonymous> (/var/app/current/node_modules/tedious/lib/connection.js:602:18)
    at emitNone (events.js:86:13)
    at MessageIO.emit (events.js:185:7)
    at ReadablePacketStream.<anonymous> (/var/app/current/node_modules/tedious/lib/message-io.js:102:16)
    at emitOne (events.js:96:13)
    at ReadablePacketStream.emit (events.js:188:7)

All 18 comments

I am having the same issue.

TypeError: Cannot read property 'release' of null
    at ConnectionPool.release (/var/app/current/node_modules/mssql/lib/base.js:199:14)
    at Request.tds.Request.err [as userCallback] (/var/app/current/node_modules/mssql/lib/tedious.js:608:25)
    at Request._this.callback (/var/app/current/node_modules/tedious/lib/request.js:47:27)
    at Connection.message (/var/app/current/node_modules/tedious/lib/connection.js:1401:27)
    at Connection.dispatchEvent (/var/app/current/node_modules/tedious/lib/connection.js:687:45)
    at MessageIO.<anonymous> (/var/app/current/node_modules/tedious/lib/connection.js:602:18)
    at emitNone (events.js:86:13)
    at MessageIO.emit (events.js:185:7)
    at ReadablePacketStream.<anonymous> (/var/app/current/node_modules/tedious/lib/message-io.js:102:16)
    at emitOne (events.js:96:13)
    at ReadablePacketStream.emit (events.js:188:7)

I am having the exact same problem, I tried to downgrade the dependency to 3.0.3 but still no luck. I have asked the question in stack overflow as well but couldn't get any help so far.

Not sure if this applies to your situation but I also had this issue recently, and it turns out it was due to a query promise not having finished before the connectionPool was closed. Either way, a nicer error message would be more helpful there.

I am having the same issue.

/Users/yangchaoguo/Documents/website/nodeserv_api/node_modules/[email protected]@mssql/lib/base.js:198
    this.pool.release(connection)
             ^

TypeError: Cannot read property 'release' of null
    at ConnectionPool.release (/Users/yangchaoguo/Documents/website/nodeserv_api/node_modules/[email protected]@mssql/lib/base.js:198:14)
    at Request.tds.Request.err [as userCallback] (/Users/yangchaoguo/Documents/website/nodeserv_api/node_modules/[email protected]@mssql/lib/tedious.js:608:25)
    at Request._this.callback (/Users/yangchaoguo/Documents/website/nodeserv_api/node_modules/[email protected]@tedious/lib/request.js:47:27)
    at Connection.message (/Users/yangchaoguo/Documents/website/nodeserv_api/node_modules/[email protected]@tedious/lib/connection.js:1401:27)
    at Connection.dispatchEvent (/Users/yangchaoguo/Documents/website/nodeserv_api/node_modules/[email protected]@tedious/lib/connection.js:687:45)
    at MessageIO.<anonymous> (/Users/yangchaoguo/Documents/website/nodeserv_api/node_modules/[email protected]@tedious/lib/connection.js:602:18)
    at emitNone (events.js:105:13)
    at MessageIO.emit (events.js:207:7)
    at ReadablePacketStream.<anonymous> (/Users/yangchaoguo/Documents/website/nodeserv_api/node_modules/[email protected]@tedious/lib/message-io.js:102:16)
    at emitOne (events.js:115:13)
    at ReadablePacketStream.emit (events.js:210:7)
    at addChunk (/Users/yangchaoguo/Documents/website/nodeserv_api/node_modules/[email protected]@readable-stream/lib/_stream_readable.js:284:12)
    at readableAddChunk (/Users/yangchaoguo/Documents/website/nodeserv_api/node_modules/[email protected]@readable-stream/lib/_stream_readable.js:271:11)
    at ReadablePacketStream.Readable.push (/Users/yangchaoguo/Documents/website/nodeserv_api/node_modules/[email protected]@readable-stream/lib/_stream_readable.js:238:10)
    at ReadablePacketStream.Transform.push (/Users/yangchaoguo/Documents/website/nodeserv_api/node_modules/[email protected]@readable-stream/lib/_stream_transform.js:146:32)
    at ReadablePacketStream._transform (/Users/yangchaoguo/Documents/website/nodeserv_api/node_modules/[email protected]@tedious/lib/message-io.js:70:16)

Same here:

..../node_modules/mssql/lib/base.js:197
    this.pool.release(connection)
             ^

TypeError: Cannot read property 'release' of null
    at ConnectionPool.release (/Users/x7n7/local_git/sam-event-lambdas/utilities/cache-department-tree/node_modules/mssql/lib/base.js:197:14)
    at Request.tds.Request.err [as userCallback] (/Users/x7n7/local_git/sam-event-lambdas/utilities/cache-department-tree/node_modules/mssql/lib/tedious.js:608:25)
    at Request._this.callback (/Users/x7n7/local_git/sam-event-lambdas/utilities/cache-department-tree/node_modules/tedious/lib/request.js:47:27)
    at Connection.message (/Users/x7n7/local_git/sam-event-lambdas/utilities/cache-department-tree/node_modules/tedious/lib/connection.js:1401:27)
    at Connection.dispatchEvent (/Users/x7n7/local_git/sam-event-lambdas/utilities/cache-department-tree/node_modules/tedious/lib/connection.js:687:45)
    at MessageIO.<anonymous> (/Users/x7n7/local_git/sam-event-lambdas/utilities/cache-department-tree/node_modules/tedious/lib/connection.js:602:18)
    at emitNone (events.js:105:13)
    at MessageIO.emit (events.js:207:7)
    at ReadablePacketStream.<anonymous> (/Users/x7n7/local_git/sam-event-lambdas/utilities/cache-department-tree/node_modules/tedious/lib/message-io.js:102:16)
    at emitOne (events.js:115:13)

The error might come from the _close method:

https://github.com/patriksimek/node-mssql/blob/85c14ff5b01b1ae0575591c7e4f1c7327cf82e51/lib/base.js#L299-L311

this.pool is set to null just after calling this.pool.drain(), so drain() isn鈥檛 done yet.
I suspect drain() to cause requests to error, reaching the following:

https://github.com/patriksimek/node-mssql/blob/85c14ff5b01b1ae0575591c7e4f1c7327cf82e51/lib/tedious.js#L455
which calls
https://github.com/patriksimek/node-mssql/blob/85c14ff5b01b1ae0575591c7e4f1c7327cf82e51/lib/base.js#L197

but at this point this.pool has been set to null.

Moving this.pool = null inside drain 's callback might have unwanted side-effects, so I won鈥檛 open a PR for it but @patriksimek might enlighten us.

Any suggestions to avoid this error?

this error is recurrent, there is some possibility of correction!

I got rid of this error by awaiting the close() call of my connection (which now in v4 is a ConnectionPool).

Encounter same issue...

Encounter same issue...

Getting the same issue, has anyone found a fix for this please?

I'm testing the following to bypass the error, so far so good:

const connection = new mssql.ConnectionPool(...);

// Patch for https://github.com/patriksimek/node-mssql/issues/467
connection._throwingClose = connection._close;
connection._close = function(callback) {
  const close = connection._throwingClose.bind(this, callback);
  if (this.pool) {
    return this.pool.drain().then(close);
  }
  else {
    return close();
  }
};

@pierre-elie where im use your code??

in node-mssql/lib/base.js line 299 ?

No I override the function in my code, when I create a connection pool to then use with requests (check ConnectionPools in this module doc)

oke thx, @pierre-elie ,btw my problem solved, update sql server 2000 service pack 4 .

Thanks @pierre-elie ! Your workaround solve the problem for me.
I only tested it in one specific case, so maybe it have some hidden side effects. If I were to encouter any, I'd update here.

this appears to have been fixed in #551

Was this page helpful?
0 / 5 - 0 ratings