sgress454 / sails-hook-autoreload

Sails JS hook to autoreload controllers and models when changed.
231 stars 44 forks source link

Autoreload failed. Got Error: Callback was already called #84

Open NguyenAnX opened 6 years ago

NguyenAnX commented 6 years ago

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)
Fr33maan commented 6 years ago

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

NguyenAnX commented 6 years ago

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

Fr33maan commented 6 years ago

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

erzzo commented 6 years ago

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"
}
gleam-ru commented 6 years ago

@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.

Fr33maan commented 6 years ago

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.

magiksd commented 6 years ago

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."

Tinostarn commented 6 years ago

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

magiksd commented 6 years ago

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

Fr33maan commented 6 years ago

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

Le 1 mars 2018 15:04, "Zeex" notifications@github.com 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 .

lvsjack commented 6 years ago

+1

oesile commented 6 years ago

+1

rock1246 commented 6 years ago

+1

l132a commented 6 years ago

waiting...

Fr33maan commented 6 years ago

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 notifications@github.com 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 .

Jakevin commented 6 years ago

+1

foobic commented 6 years ago

+1

nino-vrijman commented 6 years ago

+1

Wisperus commented 6 years ago

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!

magiksd commented 6 years ago

@Wisperus thanks, nice workaround while waiting for a fix

vpiskunov commented 6 years ago

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

sadi304 commented 6 years ago

temporary do,

archiveModelIdentity: false

in model config

fsinisi90 commented 6 years ago

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

Fr33maan commented 5 years ago

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.

codeinearts commented 5 years ago

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:

Fr33maan commented 5 years ago

I updated the readme to document that bug.

codeinearts commented 5 years ago

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

Fr33maan commented 5 years ago

Does anyone know what the archiveModelIdentity setting is for ?

andyngdz commented 5 years ago

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.