sails-hook-autoreload icon indicating copy to clipboard operation
sails-hook-autoreload copied to clipboard

Autoreload failed. Got Error: Callback was already called

Open NguyenAnX opened this issue 7 years ago • 29 comments

Every time Autoreload happens, Sails auto-migration will run but I got following error:

info: ·• Auto-migrating...  (alter)
info:    Hold tight, this could take a moment.
/Users/macOS/canvas/node_modules/parley/lib/private/Deferred.js:731
      throw e.raw;
      ^

Error: Callback was already called.
    at /Users/macOS/canvas/node_modules/async/dist/async.js:844:36
    at /Users/macOS/canvas/node_modules/sails-hook-orm/lib/initialize.js:437:27
    at /Users/macOS/canvas/node_modules/sails-hook-orm/lib/build-ontology-and-run-auto-migrations.js:133:25
    at afterMigrate (/Users/macOS/canvas/node_modules/waterline-utils/lib/auto-migrations/private/run-alter-strategy/index.js:199:14)
    at /Users/macOS/canvas/node_modules/async/dist/async.js:952:25
    at iteratorCallback (/Users/macOS/canvas/node_modules/async/dist/async.js:995:17)
    at /Users/macOS/canvas/node_modules/async/dist/async.js:847:20
    at findCallback (/Users/macOS/canvas/node_modules/waterline-utils/lib/auto-migrations/private/run-alter-strategy/index.js:115:18)
    at _tryToRunCb (/Users/macOS/canvas/node_modules/parley/lib/private/Deferred.js:518:20)
    at /Users/macOS/canvas/node_modules/parley/lib/private/Deferred.js:694:16
    at Deferred._.extend._WLModel [as _handleExec] (/Users/macOS/canvas/node_modules/waterline/lib/waterline/methods/find.js:214:20)
    at Deferred.exec (/Users/macOS/canvas/node_modules/parley/lib/private/Deferred.js:644:10)
    at simultaneouslyMigrateEachModel (/Users/macOS/canvas/node_modules/waterline-utils/lib/auto-migrations/private/run-alter-strategy/index.js:94:6)
    at /Users/macOS/canvas/node_modules/async/dist/async.js:3047:20
    at eachOfArrayLike (/Users/macOS/canvas/node_modules/async/dist/async.js:1002:13)
    at eachOf (/Users/macOS/canvas/node_modules/async/dist/async.js:1052:9)
    at Object.eachLimit (/Users/macOS/canvas/node_modules/async/dist/async.js:3111:7)
    at runAlterStrategy (/Users/macOS/canvas/node_modules/waterline-utils/lib/auto-migrations/private/run-alter-strategy/index.js:39:9)
    at Object.runAutoMigrations [as autoMigrations] (/Users/macOS/canvas/node_modules/waterline-utils/lib/auto-migrations/index.js:45:19)
    at _afterInitializingWaterline (/Users/macOS/canvas/node_modules/sails-hook-orm/lib/build-ontology-and-run-auto-migrations.js:132:20)
    at /Users/macOS/canvas/node_modules/waterline/lib/waterline.js:722:14
    at /Users/macOS/canvas/node_modules/async/dist/async.js:952:25
    at iteratorCallback (/Users/macOS/canvas/node_modules/async/dist/async.js:997:17)
    at /Users/macOS/canvas/node_modules/async/dist/async.js:847:20
    at /Users/macOS/canvas/node_modules/async/dist/async.js:952:25
    at eachOfArrayLike (/Users/macOS/canvas/node_modules/async/dist/async.js:990:13)
    at eachOf (/Users/macOS/canvas/node_modules/async/dist/async.js:1052:9)
    at Object.eachLimit (/Users/macOS/canvas/node_modules/async/dist/async.js:3111:7)

NguyenAnX avatar Nov 14 '17 09:11 NguyenAnX

What is "Sails auto-migration" ? Is it a package ? Be aware that sails-hook-autoreload is incompatible with a lot of packages.

Fr33maan avatar Nov 14 '17 09:11 Fr33maan

Auto-migration here https://sailsjs.com/documentation/concepts/models-and-orm/model-settings

NguyenAnX avatar Nov 14 '17 09:11 NguyenAnX

This should work without trouble. Please, provide a reproduction repo with minimal setup.

Fr33maan avatar Nov 14 '17 10:11 Fr33maan

same issue here. I have a fresh new project, this is my package.json:

{
  "name": "xxx",
  "private": true,
  "version": "0.0.0",
  "description": "a Sails application",
  "keywords": [],
  "dependencies": {
    "async": "2.0.1",
    "connect-redis": "3.2.0",
    "grunt": "1.0.1",
    "lodash": "3.10.1",
    "sails": "^1.0.0-40",
    "sails-ember-rest": "^1.0.12",
    "sails-hook-grunt": "^2.0.0",
    "sails-hook-orm": "^2.0.0-16",
    "sails-hook-sockets": "^1.4.0",
    "sails-postgresql": "^1.0.0-12",
    "socket.io-redis": "4.0.0"
  },
  "devDependencies": {
    "eslint": "3.19.0",
    "sails-hook-autoreload": "^1.1.0"
  },
  "scripts": {
    "start": "NODE_ENV=production node app.js",
    "test": "npm run lint && npm run custom-tests && echo 'Done.'",
    "lint": "node ./node_modules/eslint/bin/eslint . --max-warnings=0 && echo '✔  Your code looks good.'",
    "custom-tests": "echo \"(No other custom tests yet.)\" && echo",
    "debug": "node debug app.js"
  },
  "main": "app.js"
}

erzzo avatar Nov 21 '17 15:11 erzzo

@l1br3 here is a minimal example as you asked: https://github.com/gleam-ru/autoreload-issue

Steps to reproduce:

npm i
npm run dev
// edit ApiController
// save
// !!!CRAAASH!!!

Issue dissappears if you drop api/models/Model.js file.

gleam-ru avatar Dec 07 '17 15:12 gleam-ru

Thanks @gleam-ru I'm going to have a look. As I don't use sails 1.x for now I didn't dive into this earlier. If you succeed making a FIX, don't hesitate to PR or share it here.

Fr33maan avatar Dec 19 '17 12:12 Fr33maan

Hello, I have updated my dependencies and now I have the same issue. After some search, I found that the "async" module have breaking changes in its v2.0.0, and it seems to match this issue :

"Calling a callback more than once is considered an error, and an error will be thrown. This had an explicit breaking change in waterfall. If you were relying on this behavior, you should more accurately represent your control flow as an event emitter or stream."

magiksd avatar Dec 19 '17 14:12 magiksd

Same thing here, with a fresh Sails 1.0 generated project I uninstall sails-hook-autoreload until a fix is available :)

Tinostarn avatar Feb 07 '18 16:02 Tinostarn

No update on this blocking issue since months, it seems this project is dead like Sails.js, sad...

magiksd avatar Mar 01 '18 14:03 magiksd

Sorry I didn't take the time to solve it.

Le 1 mars 2018 15:04, "Zeex" [email protected] a écrit :

No update on this blocking issue since months, it seems this project is dead like Sails.js, sad...

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/sgress454/sails-hook-autoreload/issues/84#issuecomment-369600982, or mute the thread https://github.com/notifications/unsubscribe-auth/ADUhqS_sJv-KylDTHflfGzjLaS9uvLAHks5tZ__ZgaJpZM4QdCEg .

Fr33maan avatar Mar 01 '18 17:03 Fr33maan

+1

lvsjack avatar Apr 09 '18 11:04 lvsjack

+1

oesile avatar Apr 17 '18 12:04 oesile

+1

rock1246 avatar Apr 20 '18 09:04 rock1246

waiting...

l132a avatar Apr 22 '18 17:04 l132a

I'm so busy dudes. I understand its blocking for you but money comes before open source and Im sure all of you understand that.

As we have the reproduction repo, maybe one of you who getting the error can make some research and try to fix the bug.

As soon as someone has a fix I can merge PR and ask repo owner to publish on npm.

Im really sorry and I really would like to magically solve this one as it seems to completely breack this package.

Le lun. 23 avr. 2018 à 00:00, l132a [email protected] a écrit :

waiting...

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/sgress454/sails-hook-autoreload/issues/84#issuecomment-383396142, or mute the thread https://github.com/notifications/unsubscribe-auth/ADUhqQ6FdKL0BAPuMBslXTIrJk0ogr20ks5trLcigaJpZM4QdCEg .

Fr33maan avatar Apr 22 '18 17:04 Fr33maan

+1

Jakevin avatar Apr 25 '18 10:04 Jakevin

+1

foobic avatar Apr 28 '18 11:04 foobic

+1

nino-vrijman avatar May 07 '18 11:05 nino-vrijman

In './config/models.js' file I add ''

module.exports.models = { archiveModelIdentity: false } https://sailsjs.com/documentation/reference/configuration/sails-config-models It work for me!

Wisperus avatar May 30 '18 12:05 Wisperus

@Wisperus thanks, nice workaround while waiting for a fix

magiksd avatar May 30 '18 12:05 magiksd

Any update on a fix? Would be great to not disable archiveModel 🤔

vpiskunov avatar Jul 03 '18 19:07 vpiskunov

temporary do,

archiveModelIdentity: false

in model config

sadi304 avatar Jul 20 '18 18:07 sadi304

The archiveModelIdentity: false worked for me too! It would be great if this can be resolved anyway.

fsinisi90 avatar Jul 26 '18 12:07 fsinisi90

Did someone found a fix for this one ? The problem looks to be located in waterline so we need another way to reload ORM otherwise the callback is called more than once.

Fr33maan avatar Dec 13 '18 02:12 Fr33maan

In './config/models.js' file I add ''

module.exports.models = { archiveModelIdentity: false } https://sailsjs.com/documentation/reference/configuration/sails-config-models It work for me!

also worked for me using the actual sails 1.0 version.

Anyway, for those stumbling upon the same question o similar scenario of mine:

I wanted to use the sails command (eg., sails console --drop) along with the automatic reload, so I could test changes in waterline models right away after ctrl+save them.

You can use nodemon directly with the sails binary, using the normal argumments that you would pass to it. Personally, I drop this line under the package.json scripts section.

nodemon /usr/lib/node_modules/sails/bin/sails.js console --drop --redis

Hope somebody find this useful :shamrock:

codeinearts avatar Dec 30 '18 13:12 codeinearts

I updated the readme to document that bug.

Fr33maan avatar Dec 30 '18 14:12 Fr33maan

@l1br3 Thanks, for those arriving here for a solution will means a lot. :+1:

codeinearts avatar Jan 01 '19 05:01 codeinearts

Does anyone know what the archiveModelIdentity setting is for ?

Fr33maan avatar Jan 01 '19 06:01 Fr33maan

Hi @l1br3 ,

The archiveModelIdentity:

The identity of the model to use when calling .archive(). By default, this is the Archive model, an implicit model automatically defined by Sails/Waterline. Set to false to disable built-in support for soft-deletes.

andyngdz avatar Feb 16 '19 15:02 andyngdz