I am getting the below error when using request
module in NodeJs.
Error: socket hang up
at Socket.socketOnEnd (node:_http_client:524:23)
at Socket.emit (node:events:531:35)
at endReadableNT (node:internal/streams/readable:1696:12)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
code: 'ECONNRESET'
I am running my application using docker
conatiner and the code is given below.
const reqUrl = 'http://localhost:90/';
for(let i=0; i< length;i++) {
let newPayload = {
servicePath: payload['servicePath'],
payloadnumber: i+1,
schema_file_name: payload['schema_file_name']
}
let result = await uBotHandler(newPayload);
}
uBotHandler = async (payload) => {
return new Promise((resolve, reject) => {
request({
'url': reqUrl + payload['servicePath'],
'method': 'POST',
'json': true,
'body': payload
}, (error, response, body) => {
console.log('error===> ', error);
if (error) {
responseObj = {
status: 'error',
msg: `Error occurred while performing rest api call. ${error}`,
body: null
}
reject(responseObj);
} else {
responseObj = {
status: 'success',
msg: `Successfully performing rest api call.`,
body: body
};
resolve(responseObj);
}
})
});
}
Here I am sending multiple request in a loop. In first iteration of the loop the response is coming properly but in next iteration the request module is not sending any request instead its throwing the socket hangup
error. I have tried same running the application without docker and its working as expected but with the docker container its throwing such error.
Can any expert help me to resolve this issue ?