You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
debug is logging undefined as the error code #8756
In the logs above the error is undefined on one of the lines. This comes from this line which is probably going to move at some point in the future so I'll paste it here:
2017-12-06T17:17:35.977+00:00: Trace: { Error: Can't add new command when connection is in closed state
at Connection._addCommandClosedState (/home/myapp/node_modules/mysql2/lib/connection.js:158:13)
at Connection.end (/home/myapp/node_modules/mysql2/lib/connection.js:948:22)
at Utils.Promise (/home/myapp/node_modules/sequelize/lib/dialects/mysql/connection-manager.js:167:18)
at Promise._execute (/home/myapp/node_modules/sequelize/node_modules/bluebird/js/release/debuggability.js:303:9)
at Promise._resolveFromExecutor (/home/myapp/node_modules/sequelize/node_modules/bluebird/js/release/promise.js:483:18)
at new Promise (/home/myapp/node_modules/sequelize/node_modules/bluebird/js/release/promise.js:79:10)
at ConnectionManager.disconnect (/home/myapp/node_modules/sequelize/lib/dialects/mysql/connection-manager.js:166:12)
at ConnectionManager._disconnect (/home/myapp/node_modules/sequelize/lib/dialects/abstract/connection-manager.js:339:43)
at Object.destroy (/home/myapp/node_modules/sequelize/lib/dialects/abstract/connection-manager.js:114:23)
at Pool._destroy (/home/myapp/node_modules/generic-pool/lib/Pool.js:129:42)
at _trackOperation.then (/home/myapp/node_modules/generic-pool/lib/Pool.js:163:14)
at bound (domain.js:280:14)
at runBound (domain.js:293:12)
at tryCatcher (/home/myapp/node_modules/sequelize/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/home/myapp/node_modules/sequelize/node_modules/bluebird/js/release/promise.js:512:31)
at Promise._settlePromise (/home/myapp/node_modules/sequelize/node_modules/bluebird/js/release/promise.js:569:18)
at Promise._settlePromise0 (/home/myapp/node_modules/sequelize/node_modules/bluebird/js/release/promise.js:614:10)
at Promise._settlePromises (/home/myapp/node_modules/sequelize/node_modules/bluebird/js/release/promise.js:693:18)
at Async._drainQueue (/home/myapp/node_modules/sequelize/node_modules/bluebird/js/release/async.js:133:16)
at Async._drainQueues (/home/myapp/node_modules/sequelize/node_modules/bluebird/js/release/async.js:143:10)
at Immediate.Async.drainQueues (/home/myapp/node_modules/sequelize/node_modules/bluebird/js/release/async.js:17:14)
at Immediate.wrapped (/home/myapp/node_modules/newrelic/lib/transaction/tracer/index.js:184:28)
at runCallback (timers.js:672:20)
at tryOnImmediate (timers.js:645:5)
at processImmediate [as _immediateCallback] (timers.js:617:5) fatal: true }
at Connection.errorHandler (/home/myapp/node_modules/sequelize/lib/dialects/mysql/connection-manager.js:102:21)
at emitOne (events.js:96:13)
at Connection.emit (events.js:188:7)
at Connection._addCommandClosedState (/home/myapp/node_modules/mysql2/lib/connection.js:165:10)
at Connection.end (/home/myapp/node_modules/mysql2/lib/connection.js:948:22)
at Utils.Promise (/home/myapp/node_modules/sequelize/lib/dialects/mysql/connection-manager.js:167:18)
at Promise._execute (/home/myapp/node_modules/sequelize/node_modules/bluebird/js/release/debuggability.js:303:9)
at Promise._resolveFromExecutor (/home/myapp/node_modules/sequelize/node_modules/bluebird/js/release/promise.js:483:18)
at new Promise (/home/myapp/node_modules/sequelize/node_modules/bluebird/js/release/promise.js:79:10)
at ConnectionManager.disconnect (/home/myapp/node_modules/sequelize/lib/dialects/mysql/connection-manager.js:166:12)
at ConnectionManager._disconnect (/home/myapp/node_modules/sequelize/lib/dialects/abstract/connection-manager.js:339:43)
at Object.destroy (/home/myapp/node_modules/sequelize/lib/dialects/abstract/connection-manager.js:114:23)
at Pool._destroy (/home/myapp/node_modules/generic-pool/lib/Pool.js:129:42)
at _trackOperation.then (/home/myapp/node_modules/generic-pool/lib/Pool.js:163:14)
at bound (domain.js:280:14)
at runBound (domain.js:293:12)
at tryCatcher (/home/myapp/node_modules/sequelize/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/home/myapp/node_modules/sequelize/node_modules/bluebird/js/release/promise.js:512:31)
at Promise._settlePromise (/home/myapp/node_modules/sequelize/node_modules/bluebird/js/release/promise.js:569:18)
at Promise._settlePromise0 (/home/myapp/node_modules/sequelize/node_modules/bluebird/js/release/promise.js:614:10)
at Promise._settlePromises (/home/myapp/node_modules/sequelize/node_modules/bluebird/js/release/promise.js:693:18)
at Async._drainQueue (/home/myapp/node_modules/sequelize/node_modules/bluebird/js/release/async.js:133:16)
at Async._drainQueues (/home/myapp/node_modules/sequelize/node_modules/bluebird/js/release/async.js:143:10)
at Immediate.Async.drainQueues (/home/myapp/node_modules/sequelize/node_modules/bluebird/js/release/async.js:17:14)
at Immediate.wrapped (/home/myapp/node_modules/newrelic/lib/transaction/tracer/index.js:184:28)
at runCallback (timers.js:672:20)
at tryOnImmediate (timers.js:645:5)
at processImmediate [as _immediateCallback] (timers.js:617:5)
Initial idea from logs and code, I think we are trying to close a already closed connection OR a closed connection received packets in between destroy and end phase.
@sushantdhiman would that point more towards a problem with the way that I'm using this module or a possible improvement that can be made in this module?
Also, I was reading down through that file and came across this line and was wondering if instead of
or something similar to prevent a throw in the event that stream is undefined. (Unless of course it's impossible for stream to be undefined.) I mention it here and not in a separate issue in case it's related to what we're talking about in this issue - but it's probably not.
@sushantdhiman just checking in on this. Not sure if you read my previous comment. I'm trying to determine if you think that this is something that I can work around in my code or something that we need to fix in sequelize?
But I doubt that its the actual issue, connection.stream.destroyed trying to access destroyed on undefined stream will give a TypeError
I not sure about this but seems related to mysql2 OR way we handle connections OR may be pooling. Only conclusion I can draw from this error is that a closed connection is receiving packets. Will need more investigation to reach to a solid conclusion
@sushantdhiman thank you! How else can I help? Given that I am getting this error every now and then is there any other logging or data that I can gather that will help us get to the bottom of this? For example at that point in the code where we're seeing this (the console.trace() above) is there any other state information (pool/connections) that I can dump that would help us?
Its a guess (I dont have any test setup) that connection released to pool are dying (or killed by server) and sequelize then eventual got handed a closed connection.
To debug this issue I suggest enabling mysql2 debug log as well and see if connection was closed in an idle pool (by idle pool I meant that we saturate pool by doing some db ops, then let those connection eventually close) and observe if that connection was then used by sequelize.
To me this is most probable cause, as soon as sequelize detect connection is stale it request for new one and operation continues.
One cause behind this could be high evict time with low idle time as noted in documentation for pool.idle
The maximum time, in milliseconds, that a connection can be idle before being released. Use with combination of evict for proper working, for more details read coopernurse/node-pool#178 (comment)
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still an issue, just leave a comment 🙂
Activity
sushantdhiman commentedon Dec 6, 2017
Have you tried inspecting whole error, Please share that output.
On a side note, on any github code page you can press
yand it will generate a commit based permalink which wont change, like thisguyellis commentedon Dec 6, 2017
@sushantdhiman I did not know that about the
y- that is an awesome side note - thank you!How do I inspect the "whole error" - Is there an easy way to access that or do I need to modify that line to print the whole error?
sushantdhiman commentedon Dec 6, 2017
Yes
guyellis commentedon Dec 6, 2017
@sushantdhiman I updated that debug line to:
and this is what I'm seeing:
...:43:57.081Z sequelize:connection:mysql connection undefined error {"fatal":true}sushantdhiman commentedon Dec 6, 2017
can you retry with
guyellis commentedon Dec 6, 2017
@sushantdhiman here it is:
sushantdhiman commentedon Dec 7, 2017
Initial idea from logs and code, I think we are trying to close a already closed connection OR a closed connection received packets in between destroy and end phase.
guyellis commentedon Dec 7, 2017
@sushantdhiman would that point more towards a problem with the way that I'm using this module or a possible improvement that can be made in this module?
Also, I was reading down through that file and came across this line and was wondering if instead of
it should read
or something similar to prevent a throw in the event that
streamis undefined. (Unless of course it's impossible forstreamto be undefined.) I mention it here and not in a separate issue in case it's related to what we're talking about in this issue - but it's probably not.guyellis commentedon Dec 12, 2017
@sushantdhiman just checking in on this. Not sure if you read my previous comment. I'm trying to determine if you think that this is something that I can work around in my code or something that we need to fix in sequelize?
sushantdhiman commentedon Dec 13, 2017
@guyellis You can experiment with that by passing custom validate function to pooling config (http://docs.sequelizejs.com/class/lib/sequelize.js~Sequelize.html#instance-constructor-constructor)
But I doubt that its the actual issue,
connection.stream.destroyedtrying to accessdestroyedon undefinedstreamwill give a TypeErrorI not sure about this but seems related to mysql2 OR way we handle connections OR may be pooling. Only conclusion I can draw from this error is that a closed connection is receiving packets. Will need more investigation to reach to a solid conclusion
guyellis commentedon Dec 13, 2017
@sushantdhiman thank you! How else can I help? Given that I am getting this error every now and then is there any other logging or data that I can gather that will help us get to the bottom of this? For example at that point in the code where we're seeing this (the console.trace() above) is there any other state information (pool/connections) that I can dump that would help us?
sushantdhiman commentedon Dec 13, 2017
Most related issue for mysql2 sidorares/node-mysql2#447
Its a guess (I dont have any test setup) that connection released to pool are dying (or killed by server) and sequelize then eventual got handed a closed connection.
To debug this issue I suggest enabling mysql2 debug log as well and see if connection was closed in an idle pool (by idle pool I meant that we saturate pool by doing some db ops, then let those connection eventually close) and observe if that connection was then used by sequelize.
To me this is most probable cause, as soon as sequelize detect connection is stale it request for new one and operation continues.
One cause behind this could be high evict time with low idle time as noted in documentation for
pool.idleguyellis commentedon Jan 3, 2018
Thanks @sushantdhiman - I'm hoping to circle back to this in a few weeks and do some more testing and digging...
stale commentedon Apr 3, 2018
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still an issue, just leave a comment 🙂