farhadi / node-smpp

SMPP client and server implementation in node.js
MIT License
419 stars 180 forks source link

SMPP SERVER Crashed after getting this error. #168

Closed niteshtripathi1234 closed 3 years ago

niteshtripathi1234 commented 3 years ago

Client error Error: PDU length was too large (1095586128, maximum is 16384). at Function.PDU.fromStream (/app/node_modules/smpp/lib/pdu.js:49:9) at Session._extractPDUs (/app/nodemodules/smpp/lib/smpp.js:59:20) at Socket.emit (events.js:189:13) at emitReadable (_stream_readable.js:535:12) at process._tickCallback (internal/process/next_tick.js:63:19)

import as _ from 'lodash'; import { config } from '../config'; import as smpp from 'smpp'; import as controller from '../controller'; import as winston from 'winston'; import { IMessage } from 'src/interfaces';

const logger = winston.createLogger({ level: 'info', format: winston.format.json(), defaultMeta: { service: 'user-service' }, transports: [ new winston.transports.File({ filename: 'receive.log' }) ] });

export default class SMPP {

public static async createServer() {
    // const pdu = JSON.parse("{\"command_length\":70,\"command_id\":4,\"command_status\":0,\"sequence_number\":46,\"command\":\"submit_sm\",\"service_type\":\"\",\"source_addr_ton\":1,\"source_addr_npi\":1,\"source_addr\":\"16785223503\",\"dest_addr_ton\":1,\"dest_addr_npi\":1,\"destination_addr\":\"18135137238\",\"esm_class\":0,\"protocol_id\":0,\"priority_flag\":0,\"schedule_delivery_time\":\"\",\"validity_period\":\"\",\"registered_delivery\":0,\"replace_if_present_flag\":0,\"data_coding\":1,\"sm_default_msg_id\":0,\"short_message\":{\"message\":\"Hello received \"}}");
    // console.log(pdu);
    // const message: IMessage = {
    //     from: pdu.source_addr,
    //     to: pdu.destination_addr,
    //     text_content: _.get(pdu, 'short_message.message') + Math.random()
    // };
    // console.log(message);
    // controller.rabbit.sendSMStoRabbit(message);
    const server = smpp.createServer((session) => {
        session.on('bind_transceiver', (pdu) => {
            session.pause();
            if (pdu.system_id === config.system_id && pdu.password === config.password) {
                session.send(pdu.response());
                console.log('[Client connected]');
                session.resume();
                session.on('submit_sm', (pdu) => {
                    console.log('[PDU]', pdu);
                    logger.log({
                        level: 'info',
                        created: new Date(),
                        message: JSON.stringify(pdu)
                    });
                    const message: IMessage = {
                        from: pdu.source_addr,
                        to: pdu.destination_addr,
                        text_content: _.get(pdu, 'short_message.message')
                    };
                    logger.log({
                        level: 'info',
                        created: new Date(),
                        message: JSON.stringify(message)
                    });
                    controller.rabbit.sendSMStoRabbit(message);
                    session.send(pdu.response());
                });

            } else {
                session.send(pdu.response({
                    command_status: smpp.ESME_RBINDFAIL
                }));
                session.close();
                return;
            }
        });

        session.on('close', () => {
            console.log('SMPP client session close');
        });

        session.on('error', (err) => {
            console.log('Client error', err);
        });
    });
    server.listen(config.port);
    console.log('=============== Server Started =============');
}

} This was my code for SMPP.

juliangut commented 3 years ago

Hi @niteshtripathi1234

Please review issue https://github.com/farhadi/node-smpp/issues/109#issuecomment-535436988

juliangut commented 3 years ago

Answering https://github.com/farhadi/node-smpp/issues/109#issuecomment-845632992 here

Given the problem comes from fromStream method, you are receiving a PDU which length is way too long. You should contact whoever is sending that PDU to discuss the reason

Command length is read from the first 4 bytes of the packet: https://github.com/farhadi/node-smpp/blob/master/lib/pdu.js#L44

More information on the protocol itself can be found here and here

niteshtripathi1234 commented 3 years ago

Client error Error: PDU length was too large (1768176397, maximum is 16384).

is the problem resolved if I increase the limit of PDU manually? smpp.PDU.maxLength = 2000000000; please confirm.

juliangut commented 3 years ago

@niteshtripathi1234 as per my previous message:

a PDU of 1.6GB is way, way, way too long, changing maxLength should avoid receiving this error, but your real problem is receiving a PDU that big. Clearly that length is off, there is something wrong with whomever is sending that PDU

juliangut commented 3 years ago

I'm closing this issue because it was answered, no feedback was given, and new issues are being discussed from this user that leads to believe this was fixed