Skip to content

Cannot call method 'ReleaseConnection' of null #589

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

Closed
babsonmatt opened this issue Sep 11, 2013 · 5 comments · Fixed by #604
Closed

Cannot call method 'ReleaseConnection' of null #589

babsonmatt opened this issue Sep 11, 2013 · 5 comments · Fixed by #604

Comments

@babsonmatt
Copy link

I've had no problems with using pool so far but the other night I received this error, any ideas?

@dougwilson
Copy link
Member

What does the call to release look like on that line? It means the variable you are calling release on has been swapped to null in your code, perhaps because you are using a global variable, an object property, or manually set it to null at some point.

@tomislav
Copy link

tomislav commented Oct 3, 2013

I'm getting the same thing. Definitely not setting the connection to null before calling release(). Actually release() is the first function called after query(). It doesn't occur every time, maybe once every few days. MySQL problem?

TypeError: Cannot call method 'releaseConnection' of null
    at PoolConnection.release (/home/ec2-user/track-server/releases/20131002182733/node_modules/mysql/lib/PoolConnection.js:19:21)
    at Query._callback (/home/ec2-user/track-server/releases/20131002182733/server.js:419:28)
    at Query.Sequence.end (/home/ec2-user/track-server/releases/20131002182733/node_modules/mysql/lib/protocol/sequences/Sequence.js:75:24)
    at Protocol.handleNetworkError (/home/ec2-user/track-server/releases/20131002182733/node_modules/mysql/lib/protocol/Protocol.js:238:14)
    at PoolConnection.Connection._handleNetworkError (/home/ec2-user/track-server/releases/20131002182733/node_modules/mysql/lib/Connection.js:155:18)
    at Socket.EventEmitter.emit (events.js:117:20)
    at onwriteError (_stream_writable.js:233:10)
    at onwrite (_stream_writable.js:251:5)
    at WritableState.onwrite (_stream_writable.js:97:5)
    at fireErrorCallbacks (net.js:438:13)
    at Socket._destroy (net.js:472:3)
    at Object.afterWrite (net.js:718:10)

@dougwilson
Copy link
Member

Can you show your code calling release where this happens, including where the connection variable is being declared so we can see that it is not a global variable?

@tomislav
Copy link

tomislav commented Oct 3, 2013

I'm using connection pooling, and it looks like this. "pool" is global variable

var pool;

pool = mysql.createPool({
   user: 'xxx',
   password: 'xxx',
   database: 'track'
});

appsecure.post('/api/update', function(req, res) {
    /* process request and generate db query */
    pool.getConnection(function(err, connection) {
        connection.query('INSERT INTO locations (track,latitude,longitude,horizontalaccuracy,timestamp) VALUES ' + dbvalues, function(err, results, fields) {
            connection.release();
            if (err) {
              /* do something */
            } else {
              /* do something good */
            }
        });
    });
});

@dougwilson
Copy link
Member

It looks like the issue is that when a connection ends or encounters a fatal error, it is removed from the pool, but the release method doesn't check that before trying to release it (it doesn't have to do anything if already removed from the pool).

dveeden pushed a commit to dveeden/mysql that referenced this issue Jan 31, 2023
* travis: submit coverage to coveralls

* travis: fix install of coverage tools in matrix tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

3 participants