farhadi / node-smpp

SMPP client and server implementation in node.js
MIT License
417 stars 177 forks source link

Node client crash with ECONNRESET #236

Closed aTrueSeeker closed 1 year ago

aTrueSeeker commented 1 year ago

Hi, I was trying to build a node smpp client that receives incoming messages and my node app keeps crashing with ECONNRESET. Below is what my smpp.js file looks like. After running node smpp.js it starts and gets a proper connection and session.bind_transceiver also returns success but after the app is idle for a few minutes the app crashes with ECONNRESET. I am using node v18.16.1 and node-smpp v0.6.0-rc.4.

Anyone knows what causes this crash and how to handle this properly?

Code:

const session = smpp.connect({
  host: 'your_smpp_server_ip'
  port: 2775,
});

session.bind_transceiver({
  system_id: 'your_system_id',
  password: 'your_password',
}, (pdu) => {
  if (pdu.command_status === 0) {
    console.log('SMPP client bound successfully!');
  } else {
    console.error('SMPP client failed to bind:', pdu);
  }
});

// Handle incoming SMPP messages received from the SMPP server
session.on('deliver_sm', (pdu) => {
  // Handle the incoming SMPP message as required
  const sourceAddress = pdu.source_addr;
  const destinationAddress = pdu.destination_addr;
  const message = pdu.short_message.message;
  console.log('Received SMPP message:', message);
});

session.on('error', function(e: any) {
    // empty callback to catch emitted errors to prevent exit due unhandled errors
    if (e.code === "ETIMEOUT") {
        // TIMEOUT
    console.log("timed out")
    } else if (e.code === "ECONNREFUSED") {
        // CONNECTION REFUSED
    console.log("ECONNREFUSED")
    } else {
        // OTHER ERROR
    console.log("other error", e)
    }
});

Error: image

elhananjair commented 1 year ago

Hello @aTrueSeeker Adding auto_enquire_link_period: 10000, to keep the connection active may help you to fix the issue, I am guessing the problem is related to that.

aTrueSeeker commented 1 year ago

Thanks @elhananjair Yes that was the issue.

dotsinspace commented 5 months ago

I am confused....why all unique smpp have same issue...does each vendor ( reciving message ) and customer ( sending message ) should have same..enquire_link

guicuton commented 5 months ago

Some SMSC drops the connection if they don't receive any response from their enquire_link pings.

One way to solve it is sending a pdu response on event like

session.on('enquire_link', (pdu) => {
    session.send(pdu.response());
});

If your connection is still being dropped, you have to check with the SMSC the cause.

dotsinspace commented 5 months ago

Knew it @guicuton but thing is this that i am doing on this on vendor side...and some of them oftenly disconnects from our server and throws this error...some of them are super stable but some throws this error.