IbuildingsItaly / sails-db2

MIT License
10 stars 12 forks source link

A hook (`orm`) failed to load! #12

Open granteagon opened 9 years ago

granteagon commented 9 years ago

I'm getting an error trying to connect. I'm using an ssh tunnel to expose port 50000 locally, if that helps.

Sails v0.11.0 DB2 LUW v9.7

info: Starting app...

error: A hook (`orm`) failed to load!
/Users/me/Projects/test/node_modules/sails-db2/index.js:224
                if (connection.conn) connection.conn.close(function (err) {
                              ^
TypeError: Cannot read property 'conn' of undefined
    at closeConnection (/Users/me/Projects/test/node_modules/sails-db2/index.js:224:31)
    at forOwn (/Users/me/Projects/test/node_modules/sails-db2/node_modules/lodash/dist/lodash.js:2106:15)
    at Function.forEach (/Users/me/Projects/test/node_modules/sails-db2/node_modules/lodash/dist/lodash.js:3303:9)
    at Object.module.exports.adapter.teardown (/Users/me/Projects/test/node_modules/sails-db2/index.js:232:20)
    at /usr/local/lib/node_modules/sails/lib/hooks/orm/index.js:244:19
    at /usr/local/lib/node_modules/sails/node_modules/async/lib/async.js:122:13
    at _each (/usr/local/lib/node_modules/sails/node_modules/async/lib/async.js:46:13)
    at Object.async.each (/usr/local/lib/node_modules/sails/node_modules/async/lib/async.js:121:9)
    at Sails.hook.teardown (/usr/local/lib/node_modules/sails/lib/hooks/orm/index.js:241:13)
    at Sails.g (events.js:199:16)
    at Sails.emit (events.js:104:17)
    at Sails.emitter.emit (/usr/local/lib/node_modules/sails/lib/app/private/after.js:50:11)
    at /usr/local/lib/node_modules/sails/lib/app/lower.js:60:11
    at beforeShutdown (/usr/local/lib/node_modules/sails/lib/app/lower.js:35:12)
    at Sails.lower (/usr/local/lib/node_modules/sails/lib/app/lower.js:39:3)
    at Sails.bound (/usr/local/lib/node_modules/sails/node_modules/lodash/dist/lodash.js:729:21)
federico-razzoli commented 9 years ago

Please share your code, so we can try to reproduce the bug.

jthomas commented 9 years ago

I've run into this bug recently. Looking at the code, https://github.com/IbuildingsItaly/sails-db2/blob/master/index.js#L223-L232, when the teardown method is called without a name it iterates through all the available connections. The first argument to that closeConnection method becomes the entire connection object not the name. This is causing the bug referenced above.

gggordon commented 8 years ago

I submitted a pull request for this when I had the same issue https://github.com/IbuildingsItaly/sails-db2/pull/15