balderdashy / sails

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

Object.releaseConnection: Sails-Mysql Issue with join model #4312

Open pisix opened 6 years ago

pisix commented 6 years ago

Sails version:1.0.0-46 Node version:8.9.4 NPM version:5.6.0 DB adapter name: sails-mysql DB adapter version: 1.0.0-17 Operating system:MAC OS/Linux

I have two models (account and role) with one to many relationship between. I dont understand why but I have this error when I call account api

    at Object.releaseConnection (/Users/pis/futur/node_modules/sails-mysql/helpers/private/connection/release-connection.js:27:9)
    at parentQueryCb (/Users/pis/futur/node_modules/sails-mysql/helpers/join.js:228:30)
    at Object.success (/Users/pis/futur/node_modules/sails-mysql/helpers/private/query/run-native-query.js:64:14)
    at /Users/pis/futur/node_modules/machine/lib/private/help-build-machine.js:1354:30
    at _tryToRunCb (/Users/pis/futur/node_modules/parley/lib/private/Deferred.js:512:18)
    at /Users/pis/futur/node_modules/parley/lib/private/Deferred.js:734:16
    at /Users/pis/futur/node_modules/machine/lib/private/help-build-machine.js:966:24
    at Function.handlerCbs.success (/Users/pis/futur/node_modules/machine/lib/private/help-build-machine.js:826:26)
    at Query.query [as _callback] (/Users/pis/futur/node_modules/machinepack-mysql/machines/send-native-query.js:320:20)
    at Query.Sequence.end (/Users/pis/futur/node_modules/mysql/lib/protocol/sequences/Sequence.js:96:24)
    at Query._handleFinalResultPacket (/Users/pis/futur/node_modules/mysql/lib/protocol/sequences/Query.js:144:8)
    at Query.EofPacket (/Users/pis/futur/node_modules/mysql/lib/protocol/sequences/Query.js:128:8)
    at Protocol._parsePacket (/Users/pis/futur/node_modules/mysql/lib/protocol/Protocol.js:280:23)
    at Parser.write (/Users/pis/futur/node_modules/mysql/lib/protocol/Parser.js:73:12)
    at Protocol.write (/Users/pis/futur/node_modules/mysql/lib/protocol/Protocol.js:39:16)
    at Socket.<anonymous> (/Users/pis/futur/node_modules/mysql/lib/Connection.js:96:28)
    at emitOne (events.js:116:13)
    at Socket.emit (events.js:211:7)
    at addChunk (_stream_readable.js:263:12)
    at readableAddChunk (_stream_readable.js:250:11)
    at Socket.Readable.push (_stream_readable.js:208:10)
    at TCP.onread (net.js:594:20)

how can I fix it ?


sailsbot commented 6 years ago

@pisix Thanks for posting, we'll take a look as soon as possible.


For help with questions about Sails, click here. If you’re interested in hiring @sailsbot and her minions in Austin, click here.

sgress454 commented 6 years ago

Hi @pisix -- we need a little more info before we can look into this:

If this is a public project, just a link to the repo would be enough so we can reproduce the issue. Thanks!

Kinjalbagaria commented 6 years ago

Hi @pisix ,

You got any solution for this issue? I am using sails 2.0 and facing same issue when transferred code to different server.

fjafferi commented 6 years ago

I am dealing with the same issue on v1.0.1. Here is my stack 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 releaseConnection (/usr/lib/myapp/node_modules/sails-mysql/helpers/private/connection/release-connection.js:27:9)
    at Object.queryFailed (/usr/lib/myapp/node_modules/sails-mysql/helpers/private/query/run-query.js:90:7)
    at /usr/lib/myapp/node_modules/machine/lib/private/help-build-machine.js:1346:52
    at _tryToRunCb (/usr/lib/myapp/node_modules/parley/lib/private/Deferred.js:520:18)
    at /usr/lib/myapp/node_modules/parley/lib/private/Deferred.js:731:16
    at /usr/lib/myapp/node_modules/machine/lib/private/help-build-machine.js:964:35
    at Function.handlerCbs.(anonymous function) [as queryFailed] (/usr/lib/myapp/node_modules/machine/lib/private/help-build-machine.js:957:28)
    at Query.query [as _callback] (/usr/lib/myapp/node_modules/machinepack-mysql/machines/send-native-query.js:275:22)
    at Query.Sequence.end (/usr/lib/myapp/node_modules/mysql/lib/protocol/sequences/Sequence.js:96:24)
    at Query.ErrorPacket (/usr/lib/myapp/node_modules/mysql/lib/protocol/sequences/Query.js:94:8)
    at Protocol._parsePacket (/usr/lib/myapp/node_modules/mysql/lib/protocol/Protocol.js:280:23)
    at Parser.write (/usr/lib/myapp/node_modules/mysql/lib/protocol/Parser.js:73:12)
    at Protocol.write (/usr/lib/myapp/node_modules/mysql/lib/protocol/Protocol.js:39:16)
    at Socket.<anonymous> (/usr/lib/myapp/node_modules/mysql/lib/Connection.js:96:28)
    at Socket.emit (events.js:180:13)
    at addChunk (_stream_readable.js:274:12)
    at readableAddChunk (_stream_readable.js:261:11)
    at Socket.Readable.push (_stream_readable.js:218:10)
    at TCP.onread (net.js:581:20)

`

Sails version:1.0.1 Node version:9.11.1 NPM version:5.8.0 DB adapter name: sails-mysql DB adapter version: 1.0.0 Operating system: Linux

tommerkle1 commented 6 years ago

I am having the same issue when using the publish() resourceful pubsub method, however i am using postgres.

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 (/Users/tom/spare/spare-web/node_modules/sails-postgresql/helpers/private/connection/release-connection.js:27:6)
    at modifyRecordCb (/Users/tom/spare/spare-web/node_modules/sails-postgresql/helpers/create.js:228:28)
    at runQueryCb (/Users/tom/spare/spare-web/node_modules/sails-postgresql/helpers/private/query/modify-record.js:81:12)
    at Object.success (/Users/tom/spare/spare-web/node_modules/sails-postgresql/helpers/private/query/run-query.js:114:14)
    at /Users/tom/spare/spare-web/node_modules/machine/lib/private/help-build-machine.js:1354:30
    at _tryToRunCb (/Users/tom/spare/spare-web/node_modules/parley/lib/private/Deferred.js:520:18)
    at /Users/tom/spare/spare-web/node_modules/parley/lib/private/Deferred.js:755:16
    at /Users/tom/spare/spare-web/node_modules/machine/lib/private/help-build-machine.js:966:24
    at Function.handlerCbs.success (/Users/tom/spare/spare-web/node_modules/machine/lib/private/help-build-machine.js:826:26)
    at Query.query [as callback] (/Users/tom/spare/spare-web/node_modules/machinepack-postgresql/machines/send-native-query.js:128:20)
    at Query.handleReadyForQuery (/Users/tom/spare/spare-web/node_modules/pg/lib/query.js:114:10)
    at Connection.<anonymous> (/Users/tom/spare/spare-web/node_modules/pg/lib/client.js:172:19)
    at Connection.emit (events.js:160:13)
    at Socket.<anonymous> (/Users/tom/spare/spare-web/node_modules/pg/lib/connection.js:121:12)
    at Socket.emit (events.js:160:13)
    at addChunk (_stream_readable.js:269:12)
    at readableAddChunk (_stream_readable.js:256:11)
    at Socket.Readable.push (_stream_readable.js:213:10)
    at TCP.onread (net.js:599:20)

Sails version: 1.0.1 Node version: 9.4.0 NPM version: 5.6.0 DB adapter name: sails-postgresql DB adapter version: 1.0.0 Operating system: Mac OS

hg0605 commented 6 years ago

Hi, any solution to this issue yet? Facing same issue

dilame commented 5 years ago

Sails team, please, help us, this is really annoying issue. It broke my code and i even cant deal with it.

raqem commented 5 years ago

@dilame @hg0605 @tommerkle1 @fjafferi @Kinjalbagaria @pisix Hi all! This error message often appears as result of bugs in userland code, a good way to rule this out is to change your app to us await.

I think it will be easier for us all to help eachother if some model code is posted alongside the error message. Is this error occurring wail using blueprint or is this custom code?

shayanhusaini commented 5 years ago

Hi, I am also receiving this error when I try to associate permission to the role. I have many to many relations between roles and permissions and I am using custom models for associations. The endpoint is blueprint generated/permission/:permissionid/role/:roleid and I have also tried other way i.e. /role/:roleId/permission/:permissionid. It successfully creates an association in the database but I did not get a response for the API call.

Role Model:

module.exports = {
  attributes: {
    name: { type: 'string', columnType: 'varchar(255)', required: true },
    description: { type: 'string', columnType: 'varchar(255)', required: true },
    users: { collection: 'user', via: 'role' },
    isDefault: { type: 'boolean', defaultsTo: false },
    permissions: {
      collection: 'permission',
      via: 'roleId',
      through: 'rolepermission'
    }
  }
};

Permission Model:

module.exports = {
  attributes: {
    name: {
      type: 'string',
      columnType: 'varchar(255)',
      required: true,
      unique: true
    },
    roles: { collection: 'role', via: 'permissionId', through: 'rolepermission' }
  }
};

RolePermission Model:

module.exports = {
  attributes: {
    roleId: { model: 'role' },
    permissionId: { model: 'permission' }
  }
};

Here is the stack 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 (/usr/src/app/node_modules/sails-postgresql/helpers/private/connection/release-connection.js:27:6)
     at modifyRecordCb (/usr/src/app/node_modules/sails-postgresql/helpers/create-each.js:237:28)
     at runQueryCb (/usr/src/app/node_modules/sails-postgresql/helpers/private/query/modify-record.js:81:12)
     at Object.success (/usr/src/app/node_modules/sails-postgresql/helpers/private/query/run-query.js:114:14)
     at /usr/src/app/node_modules/machine/lib/private/help-build-machine.js:1517:30
     at proceedToFinalAfterExecLC (/usr/src/app/node_modules/parley/lib/private/Deferred.js:1155:14)
     at proceedToInterceptsAndChecks (/usr/src/app/node_modules/parley/lib/private/Deferred.js:913:12)
     at proceedToAfterExecSpinlocks (/usr/src/app/node_modules/parley/lib/private/Deferred.js:845:10)
     at /usr/src/app/node_modules/parley/lib/private/Deferred.js:303:7
     at /usr/src/app/node_modules/machine/lib/private/help-build-machine.js:954:24
     at Function.handlerCbs.success (/usr/src/app/node_modules/machine/lib/private/help-build-machine.js:814:26)
     at Query.query [as callback] (/usr/src/app/node_modules/machinepack-postgresql/machines/send-native-query.js:128:20)
     at Query.handleReadyForQuery (/usr/src/app/node_modules/pg/lib/query.js:124:10)
     at Connection.<anonymous> (/usr/src/app/node_modules/pg/lib/client.js:172:19)
     at Connection.emit (events.js:189:13)
     at Connection.EventEmitter.emit (domain.js:441:20)
     at Socket.<anonymous> (/usr/src/app/node_modules/pg/lib/connection.js:136:12)
     at Socket.emit (events.js:189:13)
     at Socket.EventEmitter.emit (domain.js:441:20)
     at addChunk (_stream_readable.js:284:12)
     at readableAddChunk (_stream_readable.js:265:11)
     at Socket.Readable.push (_stream_readable.js:220:10)
     at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)

Here is the original error:

 Envelope: Cannot read property 'model' of undefined

Sails version: 1.2.1 Node version: 10.15.3 DB adapter name: sails-postgresql DB adapter version: 1.0.2 Operating System: Ubuntu 16.04

SaladFrog commented 5 years ago

Dont know if this is the problem, but i got something similar. i fixed or made it work by adding columnName id (primarykey) to the many.

Lets say i have a Order

The one

module.exports = {
  attributes: {
    id: {  type: 'number',
      columnName: 'ID',
      required: true
    },
    products: {
      collection: 'product',
      via: 'order'
    }
  },
};

Id is primaryKey.

The Many

module.exports = {
    id: {
      type: 'number',
      columnName: 'ID',
      required: true
    },
    quantity: {
      type: 'number',
      columnName: 'Quantity'
    },
    order: {
      columnName: 'id',
      model: 'order'
    }
  },
};

I have to associate the id (key to connect the data) to connect them. This makes one order can have many products

johnabrams7 commented 5 years ago

@SaladFrog Thanks for the workaround! We're also currently developing a new sails-sql adapter that's compatible with MySQL & MSSQL (PostgreSQL later as well), featuring improvements and functionality beyond sails-mysql.