Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sequelize misbehaving with Node v14 #12158

Closed
kororos opened this issue Apr 23, 2020 · 54 comments
Closed

Sequelize misbehaving with Node v14 #12158

kororos opened this issue Apr 23, 2020 · 54 comments
Labels
dependency For issues and PRs. Things that are related to one or more dependencies. dialect: postgres For issues and PRs. Things that involve PostgreSQL (and do not involve all dialects). existing workaround For issues. There is a known workaround for this issue. P4: nice to have For issues that are not bugs. status: understood For issues. Applied when the issue is understood / reproducible. type: other For issues and PRs. Something that does not fit in any of the other "type:" labels.

Comments

@kororos
Copy link

kororos commented Apr 23, 2020

Today I upgraded to Node v14. However, I run into some interesting issue, most probably with Sequelize.

The problem that I run into is that in a normal execution of my app, sequelize will never return from the queries. However, if I run my program using VSCode debug, it goes through without problems. I have tried it with both v5.21.7 and v6.0.0.-beta.5

Below is the package.json that I have. Note that CLS is not used for Sequelize. I was hoping to replace CLS with Node v14 AsyncLocalStorage.

{
  "name": "backend",
  "version": "1.0.0",
  "main": "app.js",
  "author": "",
  "license": "MIT",
  "scripts": {
    "start": "babel-node src/app.js",
    "dev": "nodemon --watch src --exec BABEL_DISABLE_CACHE=1 babel-node src/app.js",
    "lint": "eslint --fix src",
    "clean": "rimraf dist",
    "build": "babel src -d dist --source-maps --copy-files",
    "build_prod": "babel src -d dist --copy-files",
    "clean-build": "yarn run clean && yarn run build"
  },
  "devDependencies": {
    "@babel/cli": "^7.8.4",
    "@babel/core": "^7.9.0",
    "@babel/node": "^7.8.7",
    "@babel/preset-env": "^7.9.5",
    "babel-polyfill": "^6.26.0",
    "eslint": "^6.8.0",
    "jsdoc": "^3.6.4",
    "rimraf": "^3.0.2"
  },
  "dependencies": {
    "babel-plugin-inline-dotenv": "^1.5.0",
    "bcrypt": "^4.0.1",
    "body-parser": "^1.19.0",
    "continuation-local-storage": "^3.2.1",
    "cors": "^2.8.5",
    "express": "^4.17.1",
    "express-session": "^1.17.0",
    "jsonwebtoken": "^8.5.1",
    "nodemon": "^2.0.3",
    "pg": "^8.0.2",
    "pg-hstore": "^2.3.3",
    "sequelize": "^5.21.7",
    "sequelize-cli": "^5.5.1"
  }
}
@Vardiak
Copy link

Vardiak commented Apr 23, 2020

I have the same problem, the sequelize.authenticate() method doesn't resolve, without any error.

@papb
Copy link
Member

papb commented Apr 23, 2020

Hmm... Can someone please create a minimal reproducible example for this?

@tevonsb
Copy link

tevonsb commented Apr 23, 2020

We are having the same issue. Will post a minimal example soon!

@tevonsb
Copy link

tevonsb commented Apr 23, 2020

I can confirm that the issue is node v14, when we downgrade to 13.x.x the issue goes away. We are using sequelize 5.21.7.

The issue we experience is: any sequelize call (sync, findOne, etc) hangs indefinitely with no error messages. For us, this caused Heroku to time out our servers main process.

@papb
Copy link
Member

papb commented Apr 23, 2020

The first hypothesis that comes to my mind is that something is wrong with Bluebird in Node 14...

@dioslibre
Copy link

dioslibre commented Apr 23, 2020

The problem I think is in pg and not sequelize. sequelize.authenticate() doesn't resolve because pg.client.connect() doesn't. sqlite on the other hand works fine.

@kororos
Copy link
Author

kororos commented Apr 23, 2020

I have some findings. I tried with a very simple project and it worked. I examined the differences between the packages of this simple project and the project where I faced the issue that I reported and I noticed that in the working project, I had pg@8.0.3. When I installed version 8.0.2 of pg it failed with node v14 (silently) but worked with version 13.13.0. With this in mind I believe that upgrading pg@8.0.3 may resolve the problem. Note, that pg@8.0.3 was only released yesterday.

When I upgraded the failing project to pg@8.0.3 it worked without a problem.

@dioslibre
Copy link

Yes @kororos, upgrading pg@8.0.3 did resolve the problem.

@sushantdhiman sushantdhiman added the dependency For issues and PRs. Things that are related to one or more dependencies. label Apr 24, 2020
@papb
Copy link
Member

papb commented Apr 26, 2020

By the way there has been some unexpected breaking changes in Node 14 regarding streams as well, not sure if related: nodejs/node#33050 and nodejs/node#32954

@ryosua
Copy link

ryosua commented May 9, 2020

Thanks @kororos ! Updating pg worked for me too.

@juberjj
Copy link

juberjj commented May 12, 2020

Thanks a lot @kororos upgrading pg@8.0.3 worked as it should.

@kd-krishna
Copy link

@tevonsb jeez thanks a lot , downgrading nodejs version did the trick. I was going mad as to what was going on.

@kororos
Copy link
Author

kororos commented Jun 3, 2020

@kd-krishna check my earlier comment above. Upgrading pg package resolved the issue (without having to downgrade node.js)

@kororos kororos closed this as completed Jun 3, 2020
@kororos kororos reopened this Jun 3, 2020
@kororos
Copy link
Author

kororos commented Jun 3, 2020

I accidentally closed the issue. Reopened it now.

davidmehren added a commit to hedgedoc/hedgedoc that referenced this issue Jun 9, 2020
With Node 14 (and seemlingly also 13) sequelize stopped resolving promises. Updating the pg package solves that.
See sequelize/sequelize#12158

Signed-off-by: David Mehren <dmehren1@gmail.com>
davidmehren added a commit to hedgedoc/hedgedoc that referenced this issue Jun 9, 2020
With Node 14 (and seemingly also 13) sequelize stopped resolving promises. Updating the pg package solves that.
See sequelize/sequelize#12158

Signed-off-by: David Mehren <dmehren1@gmail.com>
SISheogorath added a commit to hedgedoc/hedgedoc that referenced this issue Jun 9, 2020
As @davidmehren figured out, the problem that NodeJS version 14 gets
stuck while CodiMD is starting, was due to the outdated postgres
dependency. The old pg version doesn't work with node version 14 due to
an undocumented API change in the `readyState` in the socket API.

This patch updates the required dependency and this way resolves the
issue.

Reference:
sequelize/sequelize#12158
brianc/node-postgres@149f482

Signed-off-by: Sheogorath <sheogorath@shivering-isles.com>
@sushantdhiman sushantdhiman pinned this issue Jun 20, 2020
zjg added a commit to zjg/udacity-cloud-developer that referenced this issue Aug 3, 2021
@nickzelei
Copy link

I can confirm that upgrading to pg 8+ worked (with node 14.17.1)

    "pg": "8.6.0",
    "sequelize": "4.44.4"

Beforehand we had pg 6 + in one of our dependencies which caused a connect method to not resolve.

This worked for me as well. I'm upgrading a legacy system from node 12 to 14 and are almost on identical versions!

  "pg": "6.4.2",
  "sequelize": "4.44.0"

Bumping to pg@8.7.1 rectified this.

@eliasfeijo
Copy link

Same problem here, but bumping versions didn't work for me, I've tried node 14, 12 and 10, pg 8.7.1, sequelize 6.6.5... the program hangs on await connection.authenticate() and doesn't throw an error or timeout... in my case this bug started happening after I changed the database configuration of my application, but I've tested the connection running a script with pg only, and it works just fine with that same db config... I don't know what to do now, it's very frustrating that it only happens with sequelize and not with the pg script =/

@r0bynh00d
Copy link

I can confirm that the issue is node v14, when we downgrade to 13.x.x the issue goes away. We are using sequelize 5.21.7.

The issue we experience is: any sequelize call (sync, findOne, etc) hangs indefinitely with no error messages. For us, this caused Heroku to time out our servers main process.

You just saved me! I'd already spent 2+ days fighting with this issue in vain. Thank you.

@khaled
Copy link

khaled commented Sep 30, 2021

FWIW, I ran into this problem when I upgraded from node:12.18.4-slim to node:12.22.6-bullseye-slim as my base container, using sequelize 6.6.5 and pg 7.18.2. I tried updating pg to 8.7.1 and it did not help. I reverted my base container to node:12.18.4-slim and the problem went away.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 2, 2021

This issue has been automatically marked as stale because it has been open for 7 days without activity. It will be closed if no further activity occurs. If this is still an issue, just leave a comment or remove the "stale" label. 🙂

@github-actions github-actions bot added the stale label Nov 2, 2021
@WikiRik WikiRik removed the stale label Nov 15, 2021
@acharb
Copy link

acharb commented Dec 8, 2021

Looks like the issue is for other Node versions as well. I ran into this problem of sequelize.authenticate() getting stuck when I upgraded a project from Node v10 to v16 (but thankfully saw this thread 😄 ), and going from pg ^7.4.3 to ^8.7.0 fixed it for me

@ranierimazili
Copy link

Same problem here, but with mysql...
I has having the problem with Node v12.22.1, so I updated to v14.18.2 and the problem persists.

"sequelize": "^6.11.0"
"mysql2": "^2.3.3"

@ranierimazili
Copy link

ranierimazili commented Dec 17, 2021

Just found the reason for my problem...
First I was trying findOne with the following code:

const organisationInfo: ITPSharedData = await ITPSharedData.findOne({ where: { organisation_id: "8292c33e-d95a-5fe7-8f27-dd7a95c68b55" } });

The code above was hanging without any error message... Then I tried with code below:

ITPSharedData.findOne({ where: { organisation_id: "8292c33e-d95a-5fe7-8f27-dd7a95c68b55" } })
        .then(a => {
            console.log(a);
        })
        .finally(() => {
            sequelize.close();
        });

And it "worked", showing the error message and the error was that sequelize was adding in the query the columns createdAt and updatedAt, and I don't have these columns on my table, so to make sequelize work without these columns I had to define my sequelize instance as below:

const sequelize = new Sequelize("mysql://<user>:<pass>@<server>:<port>/<db>",
    {   
        define: {
            timestamps: false
        }
    }
);    

and now my code with await works

@NeurAlch
Copy link

Had the same issue, no error or any message, updating the pg package worked for me while upgrading to Node 16.

Code had:

await database.authenticate();

This is on a legacy app with Sequelize 4. A google search took me here.

@ephys
Copy link
Member

ephys commented Feb 25, 2022

I'll close this issue as it's now documented that only pg 8 supports Node >= 14: https://sequelize.org/v6/manual/dialect-specific-things.html#postgresql

I would recommend upgrading to Sequelize 6, as Sequelize < 6 is not maintained anymore and we can't guarantee that they will continue working with more recent versions of node, or pg.

@IsmaelTerreno
Copy link

My good silent errors are the worst at all for any developer after 2 days. Anyway thanks for your tips, I upgraded to :
"pg": "^8.7.3", "pg-hstore": "^2.3.4", "sequelize": "^6.20.1", "sequelize-cli": "^6.4.1",
and my node version is v18.2.0.
After making the upgrade I can see typical errors and now works perfect.

Be careful devs and I hope this helps for some one else :)

@amzbiz
Copy link

amzbiz commented Jul 25, 2022

Same issue for me, tried the error handling as recommended by others and still couldn't track down an error. Eventually identified that it was one of our internal packages node_modules that were the issue. I.e. they were old version of pg / sequelize etc. still. Once they were upgraded as well everything worked as expected.

@nitishsainani
Copy link

Issue happening with me tried almost all combinations above

@amzbiz
Copy link

amzbiz commented Aug 30, 2022

Recently upgraded to Node 16 and had this issue again, was also further modules in one of our packages that needed to be upgraded to later versions, all postgres/database related.

@lualparedes
Copy link

My good silent errors are the worst at all for any developer after 2 days. Anyway thanks for your tips, I upgraded to : "pg": "^8.7.3", "pg-hstore": "^2.3.4", "sequelize": "^6.20.1", "sequelize-cli": "^6.4.1", and my node version is v18.2.0. After making the upgrade I can see typical errors and now works perfect.

Be careful devs and I hope this helps for some one else :)

Tried this and didn't work 😞

@benjaminHarroch
Copy link

i have the same issue , after changing all package to :
"pg": "^8.7.3", "pg-hstore": "^2.3.4", "sequelize": "^6.20.1", "sequelize-cli": "^6.4.1"

my node version is v16.7

some one please can help me?

@amzbiz
Copy link

amzbiz commented Apr 2, 2023

Hi Benjamin, it's a matter of finding the right versions for your particular version of node, we were on 16.15 and using these versions which worked: "pg": "8.3.0", "pg-hstore": "2.3.3", "pg-promise": "10.9.1", "sequelize": "6.3.3". We used exact versions rather than allowing upgrade to make sure that they stayed working together.

@UmerMIB
Copy link

UmerMIB commented Apr 20, 2023

My good silent errors are the worst at all for any developer after 2 days. Anyway thanks for your tips, I upgraded to : "pg": "^8.7.3", "pg-hstore": "^2.3.4", "sequelize": "^6.20.1", "sequelize-cli": "^6.4.1", and my node version is v18.2.0. After making the upgrade I can see typical errors and now works perfect.

Be careful devs and I hope this helps for some one else :)

Didn't worked for me on ubuntu 20.04

@windsome

This comment was marked as off-topic.

@ConstantinTuca
Copy link

Upgrading the "pg" version also solved the problem for me
"pg": "8.11.3",
"sequelize": "6.37.3",
"node": "20.13.1"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependency For issues and PRs. Things that are related to one or more dependencies. dialect: postgres For issues and PRs. Things that involve PostgreSQL (and do not involve all dialects). existing workaround For issues. There is a known workaround for this issue. P4: nice to have For issues that are not bugs. status: understood For issues. Applied when the issue is understood / reproducible. type: other For issues and PRs. Something that does not fit in any of the other "type:" labels.
Projects
None yet
Development

No branches or pull requests