'Connection lost - socket hang up - ESOCKET'
See original GitHub issueBrief description of problem: I made the following observation as I updated a SELECT SQL script (using FOR JSON PATH; Outputs wrapper objects and a nested property i.e. an array of JSON objects) leveraged by a “GET” route method, which constitutes a collection of REST API endpoints. I was met with an error as the number of columns in my SELECT statement grew past the current 57, seems to have been that 57 columns is the threshold.
Expected behaviour:
I expected the totality of the 75 columns within the SELECT statement to have been transformed into the array of JSON objects , made up of wrapper objects and a nested property.
Actual behaviour:
I was met with the following error :
-
message: 'Connection lost - socket hang up',
-
code: 'ESOCKET'
I observed that my desired behaviour came to fruition with certain combinations and permutations like if removed the nested property (FYI one of the total 75 columns) of the attribute I am outputting in JSON format, but will fail if I had it included, but as expressed earlier at a total of 57 columns things work smoothly, so rather strange.
SQL: Due to propriety nature of this, I will have to include this in a pseudo format as follows:
SELECT(
SELECT CRP.COLUMN_1 ‘RECORD_PROD.COLUMN_1’, CRP.COLUMN_2 ‘RECORD_PROD.COLUMN_2’, CRP.COLUMN_3 ‘RECORD_PROD.COLUMN_3’, CRP.COLUMN_4 ‘RECORD_PROD.COLUMN_4’, CRP.COLUMN_5 ‘RECORD_PROD.COLUMN_5’, –FOR BREVITY THE GAB REPRESENTS OTHER COLUMNS CRP.COLUMN_38 ‘RECORD_PROD.COLUMN_38’ CRP.COLUMN_39 ‘RECORD_PROD.COLUMN_39’, — BELOW IS THE NEST PROPERTY ( SELECT CRP_NOTES.COMPREC_PRODUCT_NOTE_ID, CRP_NOTES.COMPREC_PRODUCT_ID, CRP_NOTES.NOTES, CRP_NOTES.USERID, CRP_NOTES.USERCODE, CRP_NOTES.DISPLAYNAME, CRP_NOTES.DATETIMESTAMP FROM NOTES CRP_NOTES WHERE CRP_NOTES.COMPREC_PRODUCT_ID = CRP.COMPLIANCERECORDSPRODUCTID
FOR JSON PATH
) ‘RECORD_PROD.NOTES’, CRP.COLUMN_41 ‘RECORD_PROD.COLUMN_41’, – FOR BREVITY COLUMNS 42 - 75
FROM PRODUCT CRP WHERE CRP.COMPLIANCERECORDSPRODUCTID = ${‘@input_parameter’}
FOR JSON PATH
) AS C_RECORDS_PROD
FYI, When this is ran via Azure Data Studio or SQL management studio things work spot on, but not via the mssql package.
Connection Pool leveraged: // promise style: const sqlPool = new sql.ConnectionPool(config.get(‘connection’)) const sqlPoolConnect = sqlPool.connect()
sqlPool.on(‘error’, err => { // … error handler console.log(err); })
–route method below router.get(‘/:id’, (req, res) => {
return sqlPoolConnect.then((pool) => {
let complianceRecordsProductID = req.params.id; if(req.query.isProduct === ‘true’) { // SQL script let sqlQuery = fetchSqlQuery(complianceRecordsProductID, req.query.isProduct); pool.request() .input(‘input_parameter’, sql.Int, complianceRecordsProductID) .query(sqlQuery, (err, result) => { // … error checks if (err) { console.log(err); } else { res.send(result); }
})
} }).catch(err => { // … error handler console.log(err); })
});
Configuration:
user: 'xxx',
password: 'xxx',
server: 'xxx',
database: 'xxx',
requestTimeout: 300000,
pool: {
max: 10,
min: 0,
idleTimeoutMillis: 300000
},
options: {
keepAlive: true,
rowCollectionOnRequestCompletion: true,
encrypt: true,
database: 'xxxxx'
}
Software versions
- NodeJS: 12.6.0
- node-mssql: 5.1.1
- SQL Server: Microsoft SQL Azure (RTM) - 12.0.2000.8
Issue Analytics
- State:
- Created 3 years ago
- Comments:5
@dhensby Oh whoa, upgrading to version 6.2.0 fixed the issue, thanks a million 👍 as I have been trying to resolve this for a good week.
Fantastic! Glad to hear it