node-mssql icon indicating copy to clipboard operation
node-mssql copied to clipboard

Connection Error: Failed to connect to xxxx:xxxx - Socket Hang Up

Open halilhanbadem opened this issue 4 years ago • 3 comments

Hello, I am using the node-mssql package in my nodejs web service. It is required to connect to the MSSQL server located on a remote server and perform user authentication. There is no problem when working with Windows. Everything is working properly. When I work with Linux alone, I get a socket hang up error. I tried to install the necessary tools for SQL Server and run a query with sqlcmd, but I got an error. Then I was able to connect by changing openssl version (1.1.1f -> 1.1.1h). I thought the problem was fixed, I saw that I kept getting the hang up error when I ran the service. When I looked at the past issues, I saw that they usually got a socket hang up error at the time of "connection lost". It was resolved with a version upgrade. The problem here was ConnectionError, which led me to the idea that there was another problem. Any ideas on this?

Thanks a lot!

Incoming error: image

Config:

var config = {
    user: 'xxxx',
    password: 'xxxx',
    server: 'xx.xx.xxx.xx', 
    database: 'xxx',
    trustServerCertificate: true,
    requestTimeout: 15000,
    stream: true,
    pool: {
      max: 10,
      min: 0,
      idleTimeoutMillis: 30000,
    },
    options: {
      keepAlive: true,
      encrypt: true,
      enableArithAbort: true,
   },
};


module.exports = config;

Software versions

  • NodeJS: 17.3.1
  • node-mssql: V7
  • SQL Server: 2017

halilhanbadem avatar Jan 12 '22 14:01 halilhanbadem

Hello, I am using the node-mssql package in my nodejs web service. It is required to connect to the MSSQL server located on a remote server and perform user authentication. There is no problem when working with Windows. Everything is working properly. When I work with Linux alone, I get a socket hang up error. I tried to install the necessary tools for SQL Server and run a query with sqlcmd, but I got an error. Then I was able to connect by changing openssl version (1.1.1f -> 1.1.1h). I thought the problem was fixed, I saw that I kept getting the hang up error when I ran the service. When I looked at the past issues, I saw that they usually got a socket hang up error at the time of "connection lost". It was resolved with a version upgrade. The problem here was ConnectionError, which led me to the idea that there was another problem. Any ideas on this?

Thanks a lot!

Incoming error: image

Config:

var config = {
    user: 'xxxx',
    password: 'xxxx',
    server: 'xx.xx.xxx.xx', 
    database: 'xxx',
    trustServerCertificate: true,
    requestTimeout: 15000,
    stream: true,
    pool: {
      max: 10,
      min: 0,
      idleTimeoutMillis: 30000,
    },
    options: {
      keepAlive: true,
      encrypt: true,
      enableArithAbort: true,
   },
};


module.exports = config;

Software versions

  • NodeJS: 17.3.1
  • node-mssql: V7
  • SQL Server: 2017

you can try

"options": { "encrypt": false }

1365436742 avatar Jan 13 '22 04:01 1365436742

@1365436742 Thanks a lot bro! From what I understand from his answer, this is how we got him to connect without encryption because there was a conflict in the communication encryption. Did I think right?

Thank you again. 💯 🚀

halilhanbadem avatar Jan 13 '22 06:01 halilhanbadem

encrypt: true is generally for Azure SQL

Glad you got it sorted

dhensby avatar Jan 13 '22 19:01 dhensby