tediousjs / node-mssql

Microsoft SQL Server client for Node.js
https://tediousjs.github.io/node-mssql
MIT License
2.23k stars 468 forks source link

[NODE v18] Failed to connect to {server} - socket hang up (code: ESOCKET) #1403

Closed MartianH closed 2 years ago

MartianH commented 2 years ago

Everything works in Node v14 and v16 (haven't used v17 as it isn't LTS or a candidate for it). This issue seems to only pop up with the latest current v18.

Note: sensitive data has been omitted.

Actual behaviour:

Error:: ConnectionError [SequelizeConnectionError]: Failed to connect to {sql_server_address}:1433 - socket hang up
    at ConnectionManager.connect ([omitted]]backend/src/node_modules/sequelize/src/dialects/mssql/connection-manager.js:138:17)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at ConnectionManager._connect ([omitted]]backend/src/node_modules/sequelize/src/dialects/abstract/connection-manager.js:326:24)
    at [omitted]]backend/src/node_modules/sequelize/src/dialects/abstract/connection-manager.js:250:32
    at ConnectionManager.getConnection ([omitted]]backend/src/node_modules/sequelize/src/dialects/abstract/connection-manager.js:280:7)
    at [omitted]]backend/src/node_modules/sequelize/src/sequelize.js:629:26
    at EmmaService.getMessage ([omitted]]backend/src/src/app/app.service.ts:105:34)
    at bootstrapFactory ([omitted]]backend/src/src/common/common.utils.ts:42:5) {
  parent: ConnectionError: Failed to connect to {sql_server_address}:1433 - socket hang up
      at Connection.socketError ([omitted]]backend/src/node_modules/tedious/src/connection.ts:2222:28)
      at Connection.socketEnd ([omitted]]backend/src/node_modules/tedious/src/connection.ts:2239:12)
      at Socket.<anonymous> ([omitted]]backend/src/node_modules/tedious/src/connection.ts:2013:37)
      at Socket.emit (node:events:549:35)
      at endReadableNT (node:internal/streams/readable:1359:12)
      at processTicksAndRejections (node:internal/process/task_queues:82:21) {
    code: 'ESOCKET',
    isTransient: undefined
  },
  original: ConnectionError: Failed to connect to {sql_server_address}:1433 - socket hang up
      at Connection.socketError ([omitted]]backend/src/node_modules/tedious/src/connection.ts:2222:28)
      at Connection.socketEnd ([omitted]]backend/src/node_modules/tedious/src/connection.ts:2239:12)
      at Socket.<anonymous> ([omitted]]backend/src/node_modules/tedious/src/connection.ts:2013:37)
      at Socket.emit (node:events:549:35)
      at endReadableNT (node:internal/streams/readable:1359:12)
      at processTicksAndRejections (node:internal/process/task_queues:82:21) {
    code: 'ESOCKET',
    isTransient: undefined
  }
}
Error:: ConnectionError [SequelizeConnectionError]: Failed to connect to {sql_server_address}:1433 - socket hang up
    at ConnectionManager.connect ([omitted]]backend/src/node_modules/sequelize/src/dialects/mssql/connection-manager.js:138:17)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at ConnectionManager._connect ([omitted]]backend/src/node_modules/sequelize/src/dialects/abstract/connection-manager.js:326:24)
    at [omitted]]backend/src/node_modules/sequelize/src/dialects/abstract/connection-manager.js:250:32
    at ConnectionManager.getConnection ([omitted]]backend/src/node_modules/sequelize/src/dialects/abstract/connection-manager.js:280:7)
    at [omitted]]backend/src/node_modules/sequelize/src/sequelize.js:629:26
    at Emma2Service.getMessage ([omitted]]backend/src/src/app/app.service.ts:105:34)
    at bootstrapFactory ([omitted]]backend/src/src/common/common.utils.ts:42:5) {
  parent: ConnectionError: Failed to connect to {sql_server_address}:1433 - socket hang up
      at Connection.socketError ([omitted]]backend/src/node_modules/tedious/src/connection.ts:2222:28)
      at Connection.socketEnd ([omitted]]backend/src/node_modules/tedious/src/connection.ts:2239:12)
      at Socket.<anonymous> ([omitted]]backend/src/node_modules/tedious/src/connection.ts:2013:37)
      at Socket.emit (node:events:549:35)
      at endReadableNT (node:internal/streams/readable:1359:12)
      at processTicksAndRejections (node:internal/process/task_queues:82:21) {
    code: 'ESOCKET',
    isTransient: undefined
  },
  original: ConnectionError: Failed to connect to {sql_server_address}:1433 - socket hang up
      at Connection.socketError ([omitted]]backend/src/node_modules/tedious/src/connection.ts:2222:28)
      at Connection.socketEnd ([omitted]]backend/src/node_modules/tedious/src/connection.ts:2239:12)
      at Socket.<anonymous> ([omitted]]backend/src/node_modules/tedious/src/connection.ts:2013:37)
      at Socket.emit (node:events:549:35)
      at endReadableNT (node:internal/streams/readable:1359:12)
      at processTicksAndRejections (node:internal/process/task_queues:82:21) {
    code: 'ESOCKET',
    isTransient: undefined
  }
}

Configuration:

The connection is handled by sequelize.

{
    username: '[OMITTED]',
    password: '{OMITTED]',
    host: '{OMITTED]',
    logging: true,
}

I have tried passing recommended options but to no avail.

options: {
    keepAlive: true,
    encrypt: true,
    enableArithAbort: true,
}

As previously mentioned: this works fine up to Node v16

Software versions

Edit: In hindsight, this could be an issue with tedious and not node-mssql. Made a ticket for it as well. if correct, this one can be closed.

dhensby commented 2 years ago

I'm going to close this issue as it's been opened in https://github.com/tediousjs/tedious/issues/1449. I agree this is likely an issue in the underlying library.

Let me know if you think this needs to be reopened