question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

'Connection lost - socket hang up - ESOCKET'

See original GitHub issue

Brief 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:closed
  • Created 3 years ago
  • Comments:5

github_iconTop GitHub Comments

2reactions
nubianMONKcommented, Jun 3, 2020

@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.

1reaction
dhensbycommented, Jun 3, 2020

Fantastic! Glad to hear it

Read more comments on GitHub >

github_iconTop Results From Across the Web

ESOCKET Connection lost - socket hang up #1035 - GitHub
I'm trying to connect node with database and ended up with this error again and again. I used async/await and promise as well...
Read more >
NodeJS to SQL Server Connection not working: socket hang ...
Try to use mssql version 6.0.1, it works on my code, but for sure we need to figure out the problem, since we...
Read more >
NodeJS - What does socket hang up actually mean - Edureka
What is a socket hang up error, first and foremost? Is it a 404 or similar error? Is it simply a case of...
Read more >
How to handle a socket hang up error in Node.js usually - Quora
Socket hang up error are usually errors when requests coming to your server ... Close the connection if you have opened any for...
Read more >
Queries and Resources - Retool Forum
Request to http://172.20.16.6/api/runQuery failed, reason: socket hang up ... Newly connecting to the Postgres DB. Works like a charm when I query ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found