I've made simple socket comm. client by using NodeJS V10.x net module and rarely seen wired symptoms which the NodeJS client was killed without any exception message. The client run on the AWS Lambda and there was no exception log or any failed message. Just it had gone....
The sequence is that
- My client connects to my ECS server and sends command data successfully.
- The server, if it received any command, it would send ACK to client. Of course it sent ACK successfully.
- Sometimes, the client had gone/killed/halted without any exception message or failed log on AWS cloud watch.
I've no idea how to trace/fix it, please help.
Here is my function code which connect/send/recv data to server and also it's being in the try...catch.
sendDirectCmd(directCmd){
return new Promise((resolve, reject)=>{
let socket = net.connect(port, hostname);
socket.setTimeout(10000); // 10 sec
socket.on('connect', async ()=>{
try{
log.info('[sendCmd] connected to ECS');
await socket.write(directCmd);
log.info('[sendCmd] Sent Cmd');
}catch(e){
e.message += `\n : (requester.sendCmd.socket.on) Failed to send Cmd \n`;
log.error('Error on connect\n', e);
reject(e);
socket.end();
}
});
socket.on('data', (data)=>{
resolve(data);
socket.end();
});
socket.on('timeout', ()=>{
reject(new Error(`socket Timeout `));
socket.end();
});
socket.on('error', (err)=>{
e.message += `\n : (requester.sendCmd.socket.error)socket Error `;
reject(err);
socket.end();
});
});
}