mirror of
https://github.com/fhmq/hmq.git
synced 2026-05-06 07:35:32 +00:00
fix: close the connection after send connection refused connack packet. (#121)
This commit is contained in:
+6
-2
@@ -279,21 +279,25 @@ func (b *Broker) handleConnection(typ int, conn net.Conn) {
|
|||||||
connack.ReturnCode = msg.Validate()
|
connack.ReturnCode = msg.Validate()
|
||||||
|
|
||||||
if connack.ReturnCode != packets.Accepted {
|
if connack.ReturnCode != packets.Accepted {
|
||||||
|
func() {
|
||||||
|
defer conn.Close()
|
||||||
err = connack.Write(conn)
|
err = connack.Write(conn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("send connack error, ", zap.Error(err), zap.String("clientID", msg.ClientIdentifier))
|
log.Error("send connack error, ", zap.Error(err), zap.String("clientID", msg.ClientIdentifier))
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
}()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if typ == CLIENT && !b.CheckConnectAuth(string(msg.ClientIdentifier), string(msg.Username), string(msg.Password)) {
|
if typ == CLIENT && !b.CheckConnectAuth(string(msg.ClientIdentifier), string(msg.Username), string(msg.Password)) {
|
||||||
connack.ReturnCode = packets.ErrRefusedNotAuthorised
|
connack.ReturnCode = packets.ErrRefusedNotAuthorised
|
||||||
|
func() {
|
||||||
|
defer conn.Close()
|
||||||
err = connack.Write(conn)
|
err = connack.Write(conn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("send connack error, ", zap.Error(err), zap.String("clientID", msg.ClientIdentifier))
|
log.Error("send connack error, ", zap.Error(err), zap.String("clientID", msg.ClientIdentifier))
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
}()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user