Leo_Lai
Leo_Lai

Reputation: 41

how to resolve go-diameter connect error: use of closed network connection?

I use go-diameter as client trying connecting to a server. I follow the example on the repo but found out there's some error happened in connecting. Here is my sample code:

cfg := &sm.Settings{
    OriginHost:       datatype.DiameterIdentity(originHost),
    OriginRealm:      datatype.DiameterIdentity(originRealm),
    VendorID:         diameterVendorID,
    ProductName:      productName,
    FirmwareRevision: firmwareRevision,
    HostIPAddresses:  []datatype.Address{
        datatype.Address(net.ParseIP(viper.GetString("my.ip"))),
    },
}

// Create the state machine (it's a diam.ServeMux) and client.
mux := sm.New(cfg)
// CER -> for sending
cli := &sm.Client{
    Dict:               dict.Default,
    Handler:            mux,
    MaxRetransmits:     3,
    RetransmitInterval: time.Second,
    EnableWatchdog:     true,
    WatchdogInterval:   5 * time.Second,

    AuthApplicationID: []*diam.AVP{
        // Advertise support for credit control application
        diam.NewAVP(avp.AuthApplicationID, avp.Mbit, 0, datatype.Unsigned32(diameterAuthAppID)), // RFC 4006
    },
}

mux.Handle(diam.CCA, handleCCA())
mux.Handle(diam.DPA, handleDPA())

// Print error reports.
go printErrors(ctx, mux.ErrorReports())

println("diameter connect....")
connect := func() (diam.Conn, error) {
    
    /*I test these two ways, both return same error*/
    return cli.DialTimeout(addr, 5*time.Second)
    //return dial(cli, addr, "", "","tcp", false)
}
c, err := connect()
if err != nil {
    println(err)
}

The code is just like the sample client code on go-diameter repo, but I will got errors as:

diameter connect....    
diameter error on x.x.x.x:3868: read tcp x.x.x.x:60766-\u003ex.x.x.x:3868: use of closed network connection

Appreciate if there's any suggestions. Thanks.

Upvotes: 1

Views: 831

Answers (1)

Leo_Lai
Leo_Lai

Reputation: 41

Answered by my self. I found the error is happened at network timeout. After I extend the timeout, the connection is OK.

Upvotes: 1

Related Questions