linxGnu / gosmpp

Smpp (3.4) Client Library for Go
Apache License 2.0
155 stars 62 forks source link

connection is closing, can not send PDU to SMSC #135

Closed parsibox closed 9 months ago

parsibox commented 9 months ago

hi dear after a period of time ( for example 1-2 day after bind ) we can not submit sms and we get error connection is closing, can not send PDU to SMSC but i create a tcp dump and see we are sending and receiving handshake but there is no log for submit_sm in tcp dump i actually can not understand what happend image

laduchesneau commented 9 months ago

We will need more info to help you, the pcap doesnt show call flow, who is sending the enquire_link ? Lets start with the basics:

parsibox commented 9 months ago

enquire_link is automatic bind type is transmitter PDU handler is OnAllPDU

laduchesneau commented 9 months ago

How do you handle unbind request in OnAllPDU ?

parsibox commented 9 months ago
OnPDU: PDUController(),

func PDUController() func(pdu2.PDU, bool) {
    return func(p pdu2.PDU, _ bool) {
        pduHeader := p.GetHeader()
        if pduHeader.CommandID.String() != "ENQUIRE_LINK_RESP" && pduHeader.CommandID.String() != "ENQUIRE_LINK" {
            file_logger_controller.AllReceivedPDUsController(map[string]interface{}{
                "CommandIDType":  pduHeader.CommandID.String(),
                "CommandLength":  pduHeader.CommandLength,
                "CommandStatus":  pduHeader.CommandStatus,
                "SequenceNumber": pduHeader.SequenceNumber,
            })
        }

        switch pd := p.(type) {
        case *pdu2.SubmitSMResp:
            SubmitResponseController(p)
        case *pdu2.GenericNack:
            //fmt.Println("GenericNack Received")
        case *pdu2.EnquireLinkResp:

        case *pdu2.BindRequest:
            BindRequestController(p)
        case *pdu2.BindResp:
            BindResponseController(p)
        case *pdu2.Unbind:
            UnbindController(p)
        case *pdu2.UnbindResp:
            UnbindResponseController(p)
        case *pdu2.DataSM:
            //fmt.Println("DataSM Received")
        case *pdu2.DeliverSM:
            DeliveryAndReceiveController(p)
            p.IsGNack()

        }

    }
}

func UnbindController(p pdu2.PDU) {
    switch pd := p.(type) {
    case *pdu2.Unbind:

        pduMap := map[string]interface{}{
            "Type":               "Unbind",
            "CommandIDType":      pd.CommandID.String(),
            "CommandLength":      pd.CommandLength,
            "CommandStatus":      pd.CommandStatus,
            "SequenceNumber":     pd.SequenceNumber,
            "OptionalParameters": pd.OptionalParameters,
            "DateTime":           time.Now().UTC().Add(time.Duration(time_zone_config.TimeZoneMinute) * time.Minute),
        }

        file_logger_controller.NewSessionSMSController(pduMap)

    }
}
laduchesneau commented 9 months ago

The code example provide is using OnPDU, not OnAllPDU. The difference is that the Unbind request from the SMSC is automatically responded too. This also means that if the bind get closed, the enquire_link should also stop. But you are saying the enquire_link continue working, just the other submits arent.

Both the loop for sending enquire_link and the submit use the same write function call in transmitable.go .

for {
        select {
        case <-ticker.C:
            eqp := pdu.NewEnquireLink()
            n, err := t.write(eqp)
            if t.check(eqp, n, err) {
                return
            }

        case p, ok := <-t.input:
            if !ok {
                return
            }

            if p != nil {
                n, err := t.write(p)
                if t.check(p, n, err) {
                    return
                }
            }
        }
    }

Are you logging something from the OnClosed func call ? If yes, are you seeing any logs ?

parsibox commented 9 months ago

yes i receive disconnect from OnClosed and i manually start create new session but when new session start submit_sm not work or connect some times not work , some times hand shake not start is there any limitation for create new session in your lib? i think there is some problem in rebind manually , we can not close old session correct

laduchesneau commented 9 months ago

i manually start create new session

You dont need to start a new session ? Let the library reconnect for you.

But when you create the new session, do you assign it back to your Submit func ? I believe this is your issue.... Your function is still pointing to the old session.

parsibox commented 9 months ago

i check it but new session hanged on connect in your library code i think something is in your lib can you create a test for have reconnect manualy?

laduchesneau commented 9 months ago

If you provide a test that shows your issue/failure, I would gladly try and help you resolve it.

If you need a new feature, feel free to submit a PR.