balderdashy / sails

Realtime MVC Framework for Node.js
https://sailsjs.com
MIT License
22.84k stars 1.95k forks source link

Sails.js Multiple callbacks from Model.getDatastore().sendNativeQuery() #7064

Open asder136 opened 3 years ago

asder136 commented 3 years ago

Node version: 12.19.0 Sails version (sails): 1.4.0 ORM hook version (sails-hook-orm): 3.0.1 Sockets hook version (sails-hook-sockets): 2.0.0 Organics hook version (sails-hook-organics): 2.2.0 Grunt hook version (sails-hook-grunt): 4.0.1 Uploads hook version (sails-hook-uploads): DB adapter & version (e.g. sails-mysql@5.55.5): sails-mysql@1.0.1 Skipper adapter & version (e.g. skipper-s3@5.55.5):


After upgrading Sails.js to v1.0 native SQL queries Model.getDatastore().sendNativeQuery() fires callback multiple times. Below is console trace:

WARNING: Something seems to be wrong with this function.
It is trying to signal that it has finished AGAIN, after
already resolving/rejecting once.
(silently ignoring this...)

To assist you in hunting this down, here is a stack trace:

    at Object.releaseConnection (C:\Users\asder\projects\warehouse\node_modules\sails-mysql\helpers\private\connection\release-connection.js:27:9)
    at parentQueryCb (C:\Users\asder\projects\warehouse\node_modules\sails-mysql\helpers\join.js:228:30)
    at Object.success (C:\Users\asder\projects\warehouse\node_modules\sails-mysql\helpers\private\query\run-native-query.js:64:14)
    at C:\Users\asder\projects\warehouse\node_modules\machine\lib\private\help-build-machine.js:1517:30
    at proceedToFinalAfterExecLC (C:\Users\asder\projects\warehouse\node_modules\parley\lib\private\Deferred.js:1155:14)
    at proceedToInterceptsAndChecks (C:\Users\asder\projects\warehouse\node_modules\parley\lib\private\Deferred.js:913:12)
    at proceedToAfterExecSpinlocks (C:\Users\asder\projects\warehouse\node_modules\parley\lib\private\Deferred.js:845:10)
    at C:\Users\asder\projects\warehouse\node_modules\parley\lib\private\Deferred.js:303:7
    at C:\Users\asder\projects\warehouse\node_modules\machine\lib\private\help-build-machine.js:954:24
    at Function.handlerCbs.success (C:\Users\asder\projects\warehouse\node_modules\machine\lib\private\help-build-machine.js:814:26)
    at Query.query [as _callback] (C:\Users\asder\projects\warehouse\node_modules\machinepack-mysql\lib\send-native-query.js:320:20)
    at Query.Sequence.end (C:\Users\asder\projects\warehouse\node_modules\mysql\lib\protocol\sequences\Sequence.js:88:24)
    at Query._handleFinalResultPacket (C:\Users\asder\projects\warehouse\node_modules\mysql\lib\protocol\sequences\Query.js:139:8)
    at Query.EofPacket (C:\Users\asder\projects\warehouse\node_modules\mysql\lib\protocol\sequences\Query.js:123:8)
    at Protocol._parsePacket (C:\Users\asder\projects\warehouse\node_modules\mysql\lib\protocol\Protocol.js:279:23)
    at Parser.write (C:\Users\asder\projects\warehouse\node_modules\mysql\lib\protocol\Parser.js:76:12)
    at Protocol.write (C:\Users\asder\projects\warehouse\node_modules\mysql\lib\protocol\Protocol.js:39:16)
    at Socket.<anonymous> (C:\Users\asder\projects\warehouse\node_modules\mysql\lib\Connection.js:103:28)
    at Socket.emit (events.js:314:20)
    at addChunk (_stream_readable.js:298:12)
    at readableAddChunk (_stream_readable.js:273:9)
    at Socket.Readable.push (_stream_readable.js:214:10)
    at TCP.onStreamRead (internal/stream_base_commons.js:188:23)

Here is the original error:

undefined

So finally I get an error in async utils that 'next' callback was called multiple times:

app.js 'handleErrors' error: Error: Callback was already called.
    at C:\Users\asder\projects\warehouse\node_modules\async\dist\async.js:318:36
    at C:\Users\asder\projects\warehouse\api\controllers\ManagerController.js:461:44
    at C:\Users\asder\projects\warehouse\api\services\TransferUtils.js:14:24
    at afterwards (C:\Users\asder\projects\warehouse\node_modules\sails-hook-orm\lib\datastore-method-utils\help-send-native-query.js:112:23)
    at C:\Users\asder\projects\warehouse\node_modules\sails-hook-orm\lib\datastore-method-utils\private\do-with-connection.js:195:18
    at C:\Users\asder\projects\warehouse\node_modules\machine\lib\private\help-build-machine.js:952:35
    at Function.handlerCbs.error (C:\Users\asder\projects\warehouse\node_modules\machine\lib\private\help-build-machine.js:742:26)
    at parley.retry (C:\Users\asder\projects\warehouse\node_modules\machine\lib\private\help-build-machine.js:1088:49)
    at parley (C:\Users\asder\projects\warehouse\node_modules\parley\lib\parley.js:140:5)
    at Object.runFn [as releaseConnection] (C:\Users\asder\projects\warehouse\node_modules\machine\lib\private\help-build-machine.js:461:23)
    at C:\Users\asder\projects\warehouse\node_modules\sails-hook-orm\lib\datastore-method-utils\private\do-with-connection.js:193:22
    at C:\Users\asder\projects\warehouse\node_modules\sails-hook-orm\lib\datastore-method-utils\private\do-with-connection.js:113:18
    at Object.success (C:\Users\asder\projects\warehouse\node_modules\sails-hook-orm\lib\datastore-method-utils\help-send-native-query.js:106:18)
    at C:\Users\asder\projects\warehouse\node_modules\machine\lib\private\help-build-machine.js:1517:30
    at proceedToFinalAfterExecLC (C:\Users\asder\projects\warehouse\node_modules\parley\lib\private\Deferred.js:1155:14)
    at proceedToInterceptsAndChecks (C:\Users\asder\projects\warehouse\node_modules\parley\lib\private\Deferred.js:913:12)
    at proceedToAfterExecSpinlocks (C:\Users\asder\projects\warehouse\node_modules\parley\lib\private\Deferred.js:845:10)
    at C:\Users\asder\projects\warehouse\node_modules\parley\lib\private\Deferred.js:303:7
    at C:\Users\asder\projects\warehouse\node_modules\machine\lib\private\help-build-machine.js:954:24
    at Function.handlerCbs.success (C:\Users\asder\projects\warehouse\node_modules\machine\lib\private\help-build-machine.js:814:26)
    at Query.query [as _callback] (C:\Users\asder\projects\warehouse\node_modules\machinepack-mysql\lib\send-native-query.js:320:20)
    at Query.Sequence.end (C:\Users\asder\projects\warehouse\node_modules\mysql\lib\protocol\sequences\Sequence.js:88:24)
    at Query._handleFinalResultPacket (C:\Users\asder\projects\warehouse\node_modules\mysql\lib\protocol\sequences\Query.js:139:8)
    at Query.EofPacket (C:\Users\asder\projects\warehouse\node_modules\mysql\lib\protocol\sequences\Query.js:123:8)
    at Protocol._parsePacket (C:\Users\asder\projects\warehouse\node_modules\mysql\lib\protocol\Protocol.js:279:23)
    at Parser.write (C:\Users\asder\projects\warehouse\node_modules\mysql\lib\protocol\Parser.js:76:12)
    at Protocol.write (C:\Users\asder\projects\warehouse\node_modules\mysql\lib\protocol\Protocol.js:39:16)
    at Socket.<anonymous> (C:\Users\asder\projects\warehouse\node_modules\mysql\lib\Connection.js:103:28)

Does anyone know WTF?

And I'm using MariaDB as a database, but previously everything was fine.

sailsbot commented 3 years ago

@gunman-ill Thanks for posting! We'll take a look as soon as possible.

In the mean time, there are a few ways you can help speed things along:

Please remember: never post in a public forum if you believe you've found a genuine security vulnerability. Instead, disclose it responsibly.

For help with questions about Sails, click here.

alxndrsn commented 3 years ago

@gunman-ill It might be relevant to know if you're using callbacks/Promises/await. Can you share an example of how you're triggering sendNativeQuery()?

eashaw commented 3 years ago

Hi @gunman-ill, would you be able to create a minimal sails app in a repo that reproduces this issue? Thanks!