Skip to content

Unhandled rejection SequelizeConnectionError: read ECONNRESET #7616

Closed

Description

@tongshouyu1019

when call functions to insert or get data from mysql at the first time, i got this error, please help

"sequelize": "~3.21.0", "mysql":

pool:{
maxConnections:10,
minConnections:1,
maxIdleTime:12000
},

Unhandled rejection SequelizeConnectionError: read ECONNRESET
at Quit._callback (/Users/tsy/devspace/builder/server/node_modules/sequelize/lib/dialects/mysql/connection-manager.js:133:30)
at Quit.Sequence.end (/Users/tsy/devspace/builder/server/node_modules/mysql/lib/protocol/sequences/Sequence.js:96:24)
at Protocol.handleNetworkError (/Users/tsy/devspace/builder/server/node_modules/mysql/lib/protocol/Protocol.js:364:14)
at Connection._handleNetworkError (/Users/tsy/devspace/builder/server/node_modules/mysql/lib/Connection.js:421:18)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at emitErrorNT (net.js:1276:8)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickCallback (internal/process/next_tick.js:98:9)
From previous event:
at ConnectionManager.disconnect (/Users/tsy/devspace/builder/server/node_modules/sequelize/lib/dialects/mysql/connection-manager.js:130:10)
at ConnectionManager.$disconnect (/Users/tsy/devspace/builder/server/node_modules/sequelize/lib/dialects/abstract/connection-manager.js:253:41)
at Object.destroy (/Users/tsy/devspace/builder/server/node_modules/sequelize/lib/dialects/abstract/connection-manager.js:99:14)
at Pool.destroy (/Users/tsy/devspace/builder/server/node_modules/generic-pool/lib/generic-pool.js:193:17)
at Pool.removeIdle [as _removeIdle] (/Users/tsy/devspace/builder/server/node_modules/generic-pool/lib/generic-pool.js:224:10)
at Timeout._onTimeout (/Users/tsy/devspace/builder/server/node_modules/generic-pool/lib/generic-pool.js:248:12)
at ontimeout (timers.js:365:14)
at tryOnTimeout (timers.js:237:5)
at Timer.listOnTimeout (timers.js:207:5)

Activity

  1. MRLuowen commented on May 11, 2017

    @MRLuowen

    i met the same questIon,
    the first , the program call self.$disconnect(connection); in the function ConnectionManager.prototype.getConnection() of the file lib/dialect/connection-manager.js.
    then, the error occour in lib/dualects/mysql/connection-manager.js

    ConnectionManager.prototype.disconnect = function(connection) {
      console.log("disconnect",connection);
      // Dont disconnect connections with an ended protocol
      // That wil trigger a connection error
      if (connection._protocol._ended) {
        return Promise.resolve();
      }
    
      return new Promise(function (resolve, reject) {
        connection.end(function(err) {
          if (err) return reject(new sequelizeErrors.ConnectionError(err));   //this position
          resolve();
        });
      });
    };
    

    i‘m not sure why happen,maybe the connection is doing some other query?so .any body come with the same question,and solve it!!
    i need helps!

    the current easy solve method is cancel run self.$disconnect(connection),but i'm not sure if there is bad effects~~~
    when i grep getConnection().there are two situations call this func.transation and this one, i really wander why you need to end it when first get server connection~~~looking foward it ~~

  2. sushantdhiman commented on May 14, 2017

    @sushantdhiman
    Contributor

    Try updating to latest v3 and report if issue still exists

  3. MRLuowen commented on May 18, 2017

    @MRLuowen

    sequelize:3.30.4, node: 7.9.0,mysql:2.13.0 .this promblem still exits,but it can work well except this error report

  4. douglasjunior commented on Jun 19, 2017

    @douglasjunior

    This promblem still exits.

        "mysql2": "^1.3.5",
        "sequelize": "^4.1.0",

    The wait timeout for MySQL is 28800 in Show variables like 'wait_timeout';

    I've tried setting up the sequelize pool idle to 10000, but it did not work.

    "pool": {
        "max": 10,
        "min": 0,
        "idle": 10000
    }
  5. Raptor2000 commented on Jun 21, 2017

    @Raptor2000

    Same problem with

     "mysql2": "^1.3.5",
    "sequelize": "^4.1.0",
    
  6. v0y4g3r commented on Jul 10, 2017

    @v0y4g3r

    Same problem

    "mysql2": "^1.3.5",
    "sequelize": "^4.2.1",
    

    Seems like when database server has already closed the connection, the client sequelize connection pool still holds that connection as ss -antup | grep 3306 shows

    tcp    ESTAB      0      0      192.168.1.108:36066              <DATABASE SERVER>:3306                users:(("node",pid=29344,fd=20))
    tcp    ESTAB      0      117    192.168.1.108:36072              <DATABASE SERVER>:3306                users:(("node",pid=29344,fd=22))
    tcp    ESTAB      0      0      192.168.1.108:36070              <DATABASE SERVER>:3306                users:(("node",pid=29344,fd=21))
    tcp    ESTAB      0      0      192.168.1.108:36068              <DATABASE SERVER>:3306                users:(("node",pid=29344,fd=19))
    tcp    ESTAB      0      117    192.168.1.108:36074              <DATABASE SERVER>:3306                users:(("node",pid=29344,fd=23))
    
  7. QuantBull commented on Sep 4, 2017

    @QuantBull
    Unhandled rejection SequelizeDatabaseError: read ECONNRESET
        at Query.formatError (D:\Projects\loankeeper\node_modules\sequelize\lib\dial
    ects\mysql\query.js:222:16)
        at Query.connection.query [as onResult] (D:\Projects\loankeeper\node_modules
    \sequelize\lib\dialects\mysql\query.js:55:23)
        at Connection._notifyError (D:\Projects\loankeeper\node_modules\mysql2\lib\c
    onnection.js:218:25)
        at Connection._handleFatalError (D:\Projects\loankeeper\node_modules\mysql2\
    lib\connection.js:178:14)
        at Connection._handleNetworkError (D:\Projects\loankeeper\node_modules\mysql
    2\lib\connection.js:183:8)
        at emitOne (events.js:115:13)
        at Socket.emit (events.js:210:7)
        at emitErrorNT (internal/streams/destroy.js:64:8)
        at _combinedTickCallback (internal/process/next_tick.js:138:11)
        at process._tickCallback (internal/process/next_tick.js:180:9)
    
    
    仍然报错在以下版本:
    "sequelize": "^4.4.2",
    "mysql2": "^1.4.0"
    
    
  8. xdamman commented on Sep 5, 2017

    @xdamman

    Might be related to #8133

  9. XidongHuang commented on Sep 7, 2017

    @XidongHuang

    I had a same problem, but it fixed when I updated sequelize to the latest version. So the versions I am using now are

    "sequelize": "4.8.2",
    "mysql2": "1.4.2",
    
  10. douglasjunior commented on Sep 18, 2017

    @douglasjunior

    For me it did not resolve after update.

        "mysql2": "~1.4.2",
        "sequelize": "~4.8.2",
    
  11. linkypi commented on Feb 7, 2018

    @linkypi

    Same problem

    "mysql2": "^1.5.2",
    "sequelize": "^4.33.0",
    
  12. nishankkumar1994 commented on Sep 22, 2018

    @nishankkumar1994

    Hi,
    I faced same issue. And here is how I fixed it for me.
    This isn't related to upgrading the version of sequelize but some other service is interrupting you while making DB connection. In my case my WiFi connection was the responsible for this issue, it was stopping other service to make TCP connection, however sequelize need to make TCP connection.
    I just disconnected the wifi and run the server.

    Worked for me!

  13. VAIMORSS commented on Nov 22, 2018

    @VAIMORSS

    It might be related to the firewall!

  14. vimmisinghani commented on Jul 25, 2019

    @vimmisinghani

    @XidongHuang Thanks.. issue solved

  15. elharony commented on Mar 18, 2020

    @elharony

    Until now, I couldn't find a working solution, and the issues are closed. Why? :)

  16. MaxGenash commented on May 11, 2020

    @MaxGenash

    Encountered a similar problem.
    Disabling the VPN helped to solve it

  17. thegkops commented on Mar 10, 2022

    @thegkops

    I am getting this error intermittently

     Error
       at Query.run (/usr/src/app/node_modules/sequelize/lib/dialects/mysql/query.js:52:25)
         at /usr/src/app/node_modules/sequelize/lib/sequelize.js:313:28 {
      name: 'SequelizeDatabaseError',
     parent: Error: read ECONNRESET
           at TLSWrap.onStreamRead (internal/stream_base_commons.js:209:20)
           at TLSWrap.callbackTrampoline (internal/async_hooks.js:131:14) {
         errno: -104,
          code: 'ECONNRESET',
        syscall: 'read',
         fatal: true,
        sql: 'SELECT 1',
         parameters: undefined
        },
       original: Error: read ECONNRESET
          at TLSWrap.onStreamRead (internal/stream_base_commons.js:209:20)
        at TLSWrap.callbackTrampoline (internal/async_hooks.js:131:14) {
         errno: -104,
        code: 'ECONNRESET',
        syscall: 'read',
        fatal: true,
        sql: 'SELECT 1',
        parameters: undefined
     } 
    
  18. chiderlin commented on Sep 28, 2022

    @chiderlin

    still facing the same issue running on cloud run (I think after connecting 28800)

    "mariadb": "^3.0.0"
    "sequelize": "^6.18.0"
    

    image

  19. ephys commented on Sep 28, 2022

    @ephys
    Member

    We haven't updated to mariadb 3 yet (#14379), try using mariadb@^2.5.6 instead

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions