question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

findOrCreate hangs, if only one connection is available

See original GitHub issue

In the example the maximum amount of conections is set to 1.

findOrCreate does not return (or maybe it will at the idle time…)

If “max:2”, then it works (giving an exception due to unique violation.

var S = require('sequelize');

var sequelize = new S('seq_test', 'passwd', '', {
    host: 'localhost',
    dialect: 'postgres',
    pool: { max: 1, 
            min: 0, idle: 10000, },
    define: {  },
});

var User = sequelize.define('User', {
    name: { type: S.STRING(50), allowNull: true, unique: true},
    pass: { type: S.STRING(50), allowNull: true},
});

sequelize.sync()
.then(function (){
    User.create({ name: 'A', pass: 'A' })
    .then(function (){
        User.findOrCreate({
          defaults: { name: 'A', pass: 'A' },
          where: { name: 'B' }
        })
        .catch(function (e){
            console.log('ERR', e);    
        })
        .then(function (){
            console.log('DONE');
            sequelize.close();
        });
    });
});

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:12 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
User4martincommented, Jun 29, 2017

“not stale”

0reactions
orajiakucommented, May 8, 2018

not stale

Read more comments on GitHub >

github_iconTop Results From Across the Web

get .findOrCreate() error - mysql - Stack Overflow
According to the link you shared, this code works, but it's not the recommended way to work with methods that return multiple arguments....
Read more >
Lucid Models - AdonisJs
findOrCreate (whereAttributes, values). Find a record, if not found a new record will be created and returned back on the fly. const ...
Read more >
Imac hangs on shut down - Apple Community - Apple Discussions
Also check your print que to see if there are any hung print jobs. Show more Less ... If you have only one...
Read more >
After Applying CPU, Java Patches, WLS Admin Server Hangs ...
Tried restoring from a complete tar of the top directory from prior the patches application but it still fails, and the log error...
Read more >
.findOrCreate() - Sails.js
findOne() , so if more than one record in the database matches the provided criteria, there will be an error explaining so. Is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found