sails: Consistency violation: Attempting to tear down a datastore (`default`) which is not currently registered with this adapter. This is usually due to a race condition in userland code (e.g. attempting to tear down the same ORM instance more than once), or it could be due to a bug in this adapter

Sails version: 1.0.2 Node version: 7.8.9 NPM version: 4.2.0 DB adapter name: N/A DB adapter version: N/A Operating system: Ubuntu 14


Updating v12 to v1.0.2 and using sails-mongo causes the app to crash when running sails lift:

error: A hook (orm) failed to load! error: Could not tear down the ORM hook. Error details: Error: Consistency violation: Attempting to tear down a datastore (default) which is not currently registered with this adapter. This is usually due to a race condition in userland code (e.g. attempting to tear down the same ORM instance more than once), or it could be due to a bug in this adapter. (If you get stumped, reach out at http://sailsjs.com/support.) at Object.teardown (/home/cabox/workspace/node_modules/sails-mongo/lib/index.js:390:19) at /home/cabox/workspace/node_modules/waterline/lib/waterline.js:758:27 at /home/cabox/workspace/node_modules/waterline/node_modules/async/dist/async.js:3047:20 at eachOfArrayLike (/home/cabox/workspace/node_modules/waterline/node_modules/async/dist/async.js:1002:13) at eachOf (/home/cabox/workspace/node_modules/waterline/node_modules/async/dist/async.js:1052:9) at Object.eachLimit (/home/cabox/workspace/node_modules/waterline/node_modules/async/dist/async.js:3111:7) at Object.teardown (/home/cabox/workspace/node_modules/waterline/lib/waterline.js:742:11) at Hook.teardown (/home/cabox/workspace/node_modules/sails-hook-orm/index.js:246:30) at Sails.wrapper (/home/cabox/workspace/node_modules/@sailshq/lodash/lib/index.js:3275:19) at Object.onceWrapper (events.js:293:19) at emitNone (events.js:86:13) at Sails.emit (events.js:188:7) at Sails.emitter.emit (/home/cabox/workspace/node_modules/sails/lib/app/private/after.js:56:26) at /home/cabox/workspace/node_modules/sails/lib/app/lower.js:67:11 at beforeShutdown (/home/cabox/workspace/node_modules/sails/lib/app/lower.js:45:12) at Sails.lower (/home/cabox/workspace/node_modules/sails/lib/app/lower.js:49:3) at Sails.wrapper [as lower] (/home/cabox/workspace/node_modules/@sailshq/lodash/lib/index.js:3275:19) at whenSailsIsReady (/home/cabox/workspace/node_modules/sails/lib/app/lift.js:68:13) at /home/cabox/workspace/node_modules/sails/node_modules/async/dist/async.js:3861:9 at /home/cabox/workspace/node_modules/sails/node_modules/async/dist/async.js:421:16 at iterateeCallback (/home/cabox/workspace/node_modules/sails/node_modules/async/dist/async.js:924:17) at /home/cabox/workspace/node_modules/sails/node_modules/async/dist/async.js:906:16 error: error: Error: Consistency violation: Unexpected error creating db connection manager:

ImplementationError: Internal error occurred while running createManager. Got non-Error: { err: ‘socketHandler’, trace: ‘’, bin: undefined, parseState: { sizeOfMessage: 759714643, bytesRead: undefined, stubBuffer: undefined } }

If you are the maintainer of “createManager”, then you can change its implementation to solve the problem (Most of the time, the solution is just to throw an actual Error instance instead. Alternatively, if the goal was to indicate a particular exception, you could throw any of the special, reserved “exit signals”-- e.g. the code name of any of your defined exits besides “error” or “success”). Otherwise, please file a bug report with the maintainer, or fork your own copy and fix that. [?] See https://sailsjs.com/support for help. at Object.registerDatastore (/home/cabox/workspace/node_modules/sails-mongo/lib/index.js:263:18) at /home/cabox/workspace/node_modules/waterline/lib/waterline.js:714:27 at /home/cabox/workspace/node_modules/waterline/node_modules/async/dist/async.js:3047:20 at eachOfArrayLike (/home/cabox/workspace/node_modules/waterline/node_modules/async/dist/async.js:1002:13) at eachOf (/home/cabox/workspace/node_modules/waterline/node_modules/async/dist/async.js:1052:9) at Object.eachLimit (/home/cabox/workspace/node_modules/waterline/node_modules/async/dist/async.js:3111:7) at Object.initialize (/home/cabox/workspace/node_modules/waterline/lib/waterline.js:650:11) at buildOntologyAndRunAutoMigrations (/home/cabox/workspace/node_modules/sails-hook-orm/lib/build-ontology-and-run-auto-migrations.js:55:7) at async.auto._buildOntology (/home/cabox/workspace/node_modules/sails-hook-orm/lib/initialize.js:456:7) at runTask (/home/cabox/workspace/node_modules/sails-hook-orm/node_modules/async/dist/async.js:1660:17) at /home/cabox/workspace/node_modules/sails-hook-orm/node_modules/async/dist/async.js:1602:17 at processQueue (/home/cabox/workspace/node_modules/sails-hook-orm/node_modules/async/dist/async.js:1612:17) at taskComplete (/home/cabox/workspace/node_modules/sails-hook-orm/node_modules/async/dist/async.js:1630:13) at /home/cabox/workspace/node_modules/sails-hook-orm/node_modules/async/dist/async.js:1653:21 at /home/cabox/workspace/node_modules/sails-hook-orm/node_modules/async/dist/async.js:339:31 at /home/cabox/workspace/node_modules/sails-hook-orm/node_modules/async/dist/async.js:847:20 at async.auto._checkAdapterCompatibility (/home/cabox/workspace/node_modules/sails-hook-orm/lib/initialize.js:428:14) at runTask (/home/cabox/workspace/node_modules/sails-hook-orm/node_modules/async/dist/async.js:1660:17) at /home/cabox/workspace/node_modules/sails-hook-orm/node_modules/async/dist/async.js:1602:17 at processQueue (/home/cabox/workspace/node_modules/sails-hook-orm/node_modules/async/dist/async.js:1612:17) at taskComplete (/home/cabox/workspace/node_modules/sails-hook-orm/node_modules/async/dist/async.js:1630:13) at /home/cabox/workspace/node_modules/sails-hook-orm/node_modules/async/dist/async.js:1653:21

at Object.error (/home/cabox/workspace/node_modules/sails-mongo/lib/index.js:268:21)
at /home/cabox/workspace/node_modules/machine/lib/private/help-build-machine.js:1514:39
at proceedToFinalAfterExecLC (/home/cabox/workspace/node_modules/parley/lib/private/Deferred.js:1149:14)
at proceedToInterceptsAndChecks (/home/cabox/workspace/node_modules/parley/lib/private/Deferred.js:909:12)
at proceedToAfterExecSpinlocks (/home/cabox/workspace/node_modules/parley/lib/private/Deferred.js:841:10)
at /home/cabox/workspace/node_modules/parley/lib/private/Deferred.js:303:7
at /home/cabox/workspace/node_modules/machine/lib/private/help-build-machine.js:952:35
at Function.handlerCbs.error (/home/cabox/workspace/node_modules/machine/lib/private/help-build-machine.js:742:26)
at connectCb (/home/cabox/workspace/node_modules/sails-mongo/lib/private/machines/create-manager.js:130:22)
at connectCallback (/home/cabox/workspace/node_modules/mongodb/lib/mongo_client.js:428:5)
at /home/cabox/workspace/node_modules/mongodb/lib/mongo_client.js:335:11
at _combinedTickCallback (internal/process/next_tick.js:73:7)
at process._tickDomainCallback (internal/process/next_tick.js:128:9)

error: Could not load Sails app. error: error: Tips: error: • First, take a look at the error message above. error: • Make sure you’ve installed dependencies with npm install. error: • Check that this app was built for a compatible version of Sails. error: • Have a question or need help? (http://sailsjs.com/support)

About this issue

  • Original URL
  • State: open
  • Created 6 years ago
  • Comments: 26 (2 by maintainers)

Most upvoted comments

Having the same issue with sails-mongo with a fresh install and sails lift:

error: A hook (`orm`) failed to load!
error: Could not tear down the ORM hook.  Error details: Error: Consistency violation: Attempting to tear down a datastore (`default`) which is not currently registered with this adapter.  This is usually due to a race condition in userland code (e.g. attempting to tear down the same ORM instance more than once), or it could be due to a bug in this adapter.  (If you get stumped, reach out at http://sailsjs.com/support.)

Mac OSX High Sierra 10.13.5 npm version 6.1.0 node version 9.8

package.json:

{
  "name": "testsails",
  "private": true,
  "version": "0.0.0",
  "description": "a Sails application",
  "keywords": [],
  "dependencies": {
    "@sailshq/connect-redis": "^3.2.1",
    "@sailshq/lodash": "^3.10.3",
    "@sailshq/socket.io-redis": "^5.2.0",
    "async": "2.0.1",
    "grunt": "1.0.1",
    "sails": "^1.0.2",
    "sails-hook-grunt": "^3.0.2",
    "sails-hook-orm": "^2.0.0-16",
    "sails-hook-sockets": "^1.4.0",
    "sails-mongo": "^1.0.1"
  },
  "devDependencies": {
    "@sailshq/eslint": "^4.19.3"
  },
  "scripts": {
    "start": "NODE_ENV=production node app.js",
    "test": "npm run lint && npm run custom-tests && echo 'Done.'",
    "lint": "eslint . --max-warnings=0 --report-unused-disable-directives && echo '✔  Your .js files look good.'",
    "custom-tests": "echo \"(No other custom tests yet.)\" && echo"
  },
  "main": "app.js",
  "repository": {
    "type": "git",
    "url": "git://github.com/tskweres/testsails.git"
  },
  "author": "tskweres",
  "license": "",
  "engines": {
    "node": ">=9.8"
  }
}

datastores.js inside the exports

default: {
   adapter: 'sails-mongo',
   url: 'mongodb://root@localhost/foo'
 }

models.js inside the exports

  attributes: {
    createdAt: { type: 'number', autoCreatedAt: true, },
    updatedAt: { type: 'number', autoUpdatedAt: true, },
    id: { type: 'string', columnName: '_id' },
  },

Hi, i had the same issue with sails version 1.2.3: one special characters such as “@” or “%” in the mogodb password was the source of the problem. My password did contain a “%”. i could lift the app after replacing it.
EDIT: i use the url parameter in my env/production.js default datastore config file.

//config/env/production.js
module.exports = {
  datastores: {
    default: {
      adapter: 'sails-mongo',
      url:'mongodb://user:Pa%%word@mongo:27017/mongobase'
}, ...

@Adimvicky @Noitidart @nagarjun Thanks a ton for all the solutions - definitely checking the stack trace closely is crucial to pinpointing the specific cause of the error. 👍

Though it’s not mongodb - I wanted to mention our latest most advanced adapter being developed is currently sails-sql - feel free to check it out!

@fardin01 you guys figure out a work around to get the app to lift?

Got this error because in my User.js model, i referred to a post collection model which i had not created at the time i tried to lift my sails app posts : { collection : 'post', via : 'owner' }, Solved the problem by commenting it out. Apparently, there are many possible reasons one could get this error. Do well to look closely at the stack trace - that was where i found my mistake. Hope this helps.

@sadeghianme As I suspected, your issue is because you are using a lowercase “u” in this line: https://github.com/sadeghianme/test/blob/master/api/controllers/UserController.js#L13. Change the code to capital “u” like Users.create({name: 'xxxxx'}).exec((err, userCreated) => {. Also, your model in api/models is called “User” but you refer to it as “Users” (plural) in your controller. Please rename your model to “Users.js”, capitalize the first letter as mentioned above and your code should work. Hope this helps.