hmq
hmq copied to clipboard
read tcp 127.0.0.1:1883->127.0.0.1:53336: use of closed network connection
when client disconnect , hmq got "read tcp 127.0.0.1:1883->127.0.0.1:53336: use of closed network connection" hmq debug :
{"level":"error","timestamp":"2020-07-17T11:19:07.308+0800","logger":"broker","caller":"broker/client.go:147","msg":"read packet error: ","error":"read tcp 127.0.0.1:1883->127.0.0.1:53336: use of closed network connection","ClientID":"spuerClientId001","stacktrace":"github.com/fhmq/hmq/broker.(*client).readLoop\n\t/Users/aureso/Documents/goproject/hsbmqtt/broker/client.go:147\ngithub.com/fhmq/hmq/broker.(*Broker).handleConnection\n\t/Users/aureso/Documents/goproject/hsbmqtt/broker/broker.go:371"}
my debug code in client.go after line 141:
fmt.Println(nc)
fmt.Println(c.status)
packet, err := packets.ReadPacket(nc)
if err != nil {
log.Error("read packet error: ", zap.Error(err), zap.String("ClientID", c.info.clientID))
msg := &Message{
client: c,
packet: DisconnectdPacket,
}
b.SubmitWork(c.info.clientID, msg)
return
}
c.status always 1,so i think code
packet, err := packets.ReadPacket(nc)
if err != nil {
log.Error("read packet error: ", zap.Error(err), zap.String("ClientID", c.info.clientID))
msg := &Message{
client: c,
packet: DisconnectdPacket,
}
b.SubmitWork(c.info.clientID, msg)
return
}
never normal for Disconnect action
I just changed this error message to a readable information message.
if err != nil {
if err == io.EOF {
log.Info("TCP Connection Closed", zap.String("ClientID", c.info.clientID))
} else {
log.Error("read packet error: ", zap.Error(err), zap.String("ClientID", c.info.clientID))
}
msg := &Message{
client: c,
packet: DisconnectedPacket,
}
b.SubmitWork(c.info.clientID, msg)
return
}
anyone know/find fix for above issue? i tried @jzhenxing quick fix above, but still same error when attempting to to mqtt_pub to broker.