Skip to content

sequelize.sync does not return error if DB unavailable #1207

Closed

Description

@overlookmotel

When database is unavailable, the following code throws 'TypeError: Uncaught, unspecified "error" event':

var Sequelize = require('sequelize');
var sequelize = new Sequelize('db', 'user', 'pass');

var Project = sequelize.define('Project', {title: Sequelize.STRING});
var Task = sequelize.define('Task', {title: Sequelize.STRING});

sequelize.sync()
  .success(function() {console.log('DB synced')})
  .error(function(err) {console.log('Error:', err)});

Whereas when you remove the definition of either Project or Task, it runs the .error function as expected.

This makes it difficult to catch and deal with a database connection error.

Activity

  1. overlookmotel commented on Jan 6, 2014

    @overlookmotel
    ContributorAuthor

    ...on Sequelize 1.7.0-beta7, MySQL 5.6.14, OS X 10.8.5

  2. mickhansen commented on Jan 6, 2014

    @mickhansen
    Contributor

    If you remove 1 of your 2 model definitions it will correctly emit a database error? Wth

  3. overlookmotel commented on Jan 6, 2014

    @overlookmotel
    ContributorAuthor

    Yup! Wierd isn't it? As far as I can see it only happens when there is a failure to connect to the database. Other errors e.g. no permission to CREATE tables are emitted as expected.

  4. mickhansen commented on Jan 7, 2014

    @mickhansen
    Contributor

    Well hopefully it's reproduceable, i'll take a look at it :)

  5. mickhansen commented on Jan 7, 2014

    @mickhansen
    Contributor

    But yeah connection errors are an issue in general it seems

  6. overlookmotel commented on Jan 7, 2014

    @overlookmotel
    ContributorAuthor

    I don't think it's a major issue as you can work around it by syncing a single model first to test the connection, and then doing the full sync.

    I'm sure everyone has bigger fish to fry - I just figured it might be useful to post issues for any bugs I find so people have some vague background awareness...

  7. mickhansen commented on Jan 7, 2014

    @mickhansen
    Contributor

    It's not a major issue, but a minor annoyance ;) We're probably going to do a feature freeze for 1.7.0 now and get out a RC - So fixing a few bugs wouldn't hurt.

  8. mickhansen commented on Jan 7, 2014

    @mickhansen
    Contributor

    Issues that gives us a easily reproduceable test case are always more than welcome :)

  9. mickhansen commented on Jan 18, 2014

    @mickhansen
    Contributor

    @overlookmotel This is with postgres right?

  10. overlookmotel commented on Jan 18, 2014

    @overlookmotel
    ContributorAuthor

    No, this was Sequelize 1.7.0-beta7, MySQL 5.6.14, OS X 10.8.5.
    I'll update to rc2 and see if it's solved - will let you know.

  11. overlookmotel commented on Jan 18, 2014

    @overlookmotel
    ContributorAuthor

    No, I'm afraid the problem is still there with 1.7.0-rc2 on MySQL

    When there is more than one model to sync, neither success(), error() or done() is called and there is an uncaught exception.
    When there is only one model, error()/done() is called, but there is still an uncaught exception as well.

    Here's the error message (same stack trace whether there is one model or two):

    TypeError: Uncaught, unspecified "error" event.
        at TypeError (<anonymous>)
        at EventEmitter.emit (events.js:74:15)
        at Handshake._callback (/Programming/test/node_modules/sequelize/lib/dialects/mysql/connector-manager.js:278:19)
        at Handshake.Sequence.end (/Programming/test/node_modules/mysql/lib/protocol/sequences/Sequence.js:75:24)
        at Protocol.handleNetworkError (/Programming/test/node_modules/mysql/lib/protocol/Protocol.js:255:14)
        at Connection._handleNetworkError (/Programming/test/node_modules/mysql/lib/Connection.js:187:18)
        at Socket.EventEmitter.emit (events.js:117:20)
        at net.js:441:14
        at process._tickCallback (node.js:415:13)
    
  12. mickhansen commented on Jan 18, 2014

    @mickhansen
    Contributor

    Hmm, i wasn't able to reproduce that with a unit test that matched your gist.
    Could you perhaps try and create a PR with a failing unit test?

  13. overlookmotel commented on Jan 18, 2014

    @overlookmotel
    ContributorAuthor

    OK I'll try! Never wrote a unit test, or did a pull request!
    It'll take me some time to figure it out...

  14. overlookmotel commented on Jan 18, 2014

    @overlookmotel
    ContributorAuthor

    Could you post your unit test here to give me a starting point?

  15. mickhansen commented on Jan 19, 2014

    @mickhansen
    Contributor
  16. overlookmotel commented on Jan 21, 2014

    @overlookmotel
    ContributorAuthor

    Pull request for a test: #1278

    NB the problem I describe doesn't happen if the db username/password are wrong, but when the database cannot be reached at all e.g. db server has crashed or connection details (port etc) are wrong

  17. sdepold commented on Jan 21, 2014

    @sdepold
    Member

    Isn't this #1012 ?

  18. mickhansen commented on Jan 21, 2014

    @mickhansen
    Contributor

    @sdepold dnu, but @overlookmotel provided an actual failing test case so i'll look at that :)

  19. overlookmotel commented on Jan 21, 2014

    @overlookmotel
    ContributorAuthor

    @sdepold Ah yes, you're right. Sorry, didn't notice the issue had already been reported.

  20. sdepold commented on Jan 22, 2014

    @sdepold
    Member

    No problem.

  21. mickhansen commented on Jan 22, 2014

    @mickhansen
    Contributor

    Should be fixed by #1282

  22. Roam-Cooper commented on Jun 22, 2014

    @Roam-Cooper

    I'm experiencing this issue on Sequelize 1.7.9, but relatively recent versions of postgres (9.3.4-4, 9.1.13-4 are the ones I have tried), x86 and x86-64. I am on Windows 7 as well.

    When I run sync without defining any models, it completes fine. When I define one model, it never calls back. I switched to node x86 and postgres x86 after a string of Assertion failed:0 issues referencing a g:\jenkins\workspace folder that does not exist. Unsolvable for me.

    I can provide more details if necessary.

  23. mickhansen commented on Jun 23, 2014

    @mickhansen
    Contributor

    That is strange @Roam-Cooper. If you could provide a single self contained test file for @janmeier to try out that would be great (jan is the only one with a windoze box)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

type: bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions