tediousjs / node-mssql

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

NodeJS v18 Broke some connections (Socket Hang Up) #1440

Closed firesightstudios closed 1 year ago

firesightstudios commented 1 year ago

I can confirm that going from Node version 16.6 to Node version 18.12.1 breaks connecting to my DB. Using mssql 9.0.1.

What's a little strange is: while I'm on node v18, I have 2 databases I'm trying to connect to and only one of them breaks, I'm assuming this is driver related? Because of the sql server versions ?

Both DB connections work on node 16.6. Only one connection works on node 18.12.1

I would have to reach out to the server maintainers to find out server information to supply here.

Error creating connection pool ConnectionError: Failed to connect to mydb:1433 - socket hang up

 at C:\Users\me\IdeaProjects\myproj\node_modules\mssql\lib\tedious\connection-pool.js:70:17                
    at Connection.onConnect (C:\Users\me\IdeaProjects\myproj\node_modules\tedious\lib\connection.js:1020:9)   
    at Object.onceWrapper (node:events:628:26)                                                                                        
    at Connection.emit (node:events:513:28)                                                                                           
    at Connection.emit (C:\Users\me\IdeaProjects\myproj\node_modules\tedious\lib\connection.js:1048:18)       
    at Connection.socketError (C:\Users\me\IdeaProjects\myproj\node_modules\tedious\lib\connection.js:1399:12)
    at Connection.socketEnd (C:\Users\me\IdeaProjects\myproj\node_modules\tedious\lib\connection.js:1419:12)
    at Socket.<anonymous> (C:\Users\me\IdeaProjects\myproj\node_modules\tedious\lib\connection.js:1161:16)
    at Socket.emit (node:events:525:35)
    at endReadableNT (node:internal/streams/readable:1359:12)

I can confirm not changing a line of code and switching Node versions from 18.12.1 to 16.6 resolves this problem.

const SQL = require("mssql");
const MY_CONFIG = {
    server: process.env.SQL_SERVER_NAME,
    database: process.env.SQL_DATABASE,
    user: process.env.SQL_USER_NAME,
    password: process.env.SQL_PASSWORD,
    options: {
        encrypt: true,
        trustServerCertificate: true,
        trustedConnection: true
    }
};
const APP_POOL = new SQL.ConnectionPool(MY_CONFIG);

//start server
APP_POOL.connect().then(function(myPool) {
    APP.locals.myDB = myPool;
    APP.listen(process.env.PORT, function () {
        console.log(`Server running on port: ${process.env.PORT}`);
    })
}).catch(function(err) {
    console.error('Error creating connection pool', err)
});

Software versions

dhensby commented 1 year ago

If anything it points to an issue with the node runtime. As the driver you're using is tedious, it's probably best this issue is raised there as they may have more insight into the connections/sockets and what might be going on to cause concurrent sockets to break in Node v18?

ysageev commented 1 year ago

I am having the same problem. Just upgraded to Node 18 5 minutes ago.

UPDATE:

Set options, encrypt: false fixes this for me:

Tedious thread: https://github.com/tediousjs/tedious/issues/1449#issuecomment-1164879792

dhensby commented 1 year ago

Thanks for the tedious link.

It looks like the cause of this is known and is outside the scope of this library (and possibly the tedious driver).

If there's an easy way to provide a working fix or at least a readme update to help mitigate the issue, I'd be happy to add that to the docs.

billnbell commented 1 year ago

cryptoCredentialsDetails: { ciphers: 'DEFAULT@SECLEVEL=0', } See thread. https://github.com/tediousjs/tedious/issues/1449#issuecomment-1164879792