wind-c / comqtt

A lightweight, high-performance go mqtt server(v3.0|v3.1.1|v5.0) supporting distributed cluster
MIT License
972 stars 53 forks source link

Disconnecting while Kafka bridge turned on causes a panic #72

Closed jlundy2 closed 1 year ago

jlundy2 commented 1 year ago

If bridge-way is set to 1, disconnecting an MQTT client causes the following error:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0xbbee38]

goroutine 51 [running]:
github.com/wind-c/comqtt/v2/plugin/bridge/kafka.(*Bridge).OnDisconnect(0xc000382960, 0xc00011e780, {0x0, 0x0}, 0x68?)
     /app/plugin/bridge/kafka/kafka.go:279 +0x98
github.com/wind-c/comqtt/v2/mqtt.(*Hooks).OnDisconnect(0xc00030c2a0?, 0xd628c1?, {0x0, 0x0}, 0x3?)
     /app/mqtt/hooks.go:265 +0x13c
github.com/wind-c/comqtt/v2/mqtt.(*Server).attachClient(0xc000382190, 0xc00011e780, {0xd54ca3, 0x3})
    /app/mqtt/server.go:381 +0x7c5
github.com/wind-c/comqtt/v2/mqtt.(*Server).EstablishConnection(0x8747ae?, {0xd54ca3, 0x3}, {0xe712a8?, 0xc000012008?})
     /app/mqtt/server.go:311 +0x65
github.com/wind-c/comqtt/v2/mqtt/listeners.(*TCP).Serve.func1()
     /app/mqtt/listeners/tcp.go:84 +0x47
created by github.com/wind-c/comqtt/v2/mqtt/listeners.(*TCP).Serve
     /app/mqtt/listeners/tcp.go:83 +0x145

Not sure if it's because the client has already disconnected or what.

wind-c commented 1 year ago

The problem is that panic occurs when err is nil. Have fixed it.