wind-c / comqtt

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

Panic with embedded broker #20

Closed james7272 closed 1 year ago

james7272 commented 1 year ago

With the broker embedded into my app I get the following panic during testing, both when publishing directly (server.Publish) or using the paho client.

The i.ks list gets filled with *InflightMessage (inflight_map.go:34) but after reading tries to cast to uint16 (inflight_map.go:32)

panic: interface conversion: interface {} is *clients.InflightMessage, not uint16

goroutine 50 [running]:
github.com/wind-c/comqtt/server/internal/clients.(*InflightMap).Set(0xc0007ca060, 0x21c, 0xc0006b1ce0)
    /home/james/projects/web-mon/server/vendor/github.com/wind-c/comqtt/server/internal/clients/inflight_map.go:32 +0x2fe
github.com/wind-c/comqtt/server.(*Server).publishToSubscribers(_, {{0x2b4, 0x3, 0x1, 0x0, 0x0}, {0x0, 0x0, 0x0}, {0x0, ...}, ...})
    /home/james/projects/web-mon/server/vendor/github.com/wind-c/comqtt/server/server.go:654 +0x498
github.com/wind-c/comqtt/server.(*Server).processPublish(_, _, {{0x2b4, 0x3, 0x1, 0x0, 0x0}, {0x0, 0x0, 0x0}, ...})
    /home/james/projects/web-mon/server/vendor/github.com/wind-c/comqtt/server/process.go:149 +0x678
github.com/wind-c/comqtt/server.(*Server).processPacket(_, _, {{0x2b4, 0x3, 0x1, 0x0, 0x0}, {0x0, 0x0, 0x0}, ...})
    /home/james/projects/web-mon/server/vendor/github.com/wind-c/comqtt/server/process.go:28 +0x138
github.com/wind-c/comqtt/server/internal/clients.(*Client).Read(0xc0007cc000, 0xc0007f7940)
    /home/james/projects/web-mon/server/vendor/github.com/wind-c/comqtt/server/internal/clients/clients.go:401 +0x19d
github.com/wind-c/comqtt/server.(*Server).EstablishConnection(0xc000140370, {0xa1d4a4, 0x4}, {0xae60f8, 0xc00033e008}, {0xae2260?, 0xe8b340?})
    /home/james/projects/web-mon/server/vendor/github.com/wind-c/comqtt/server/server.go:362 +0x10f2
github.com/wind-c/comqtt/server/listeners.(*TCP).Serve.func1()
    /home/james/projects/web-mon/server/vendor/github.com/wind-c/comqtt/server/listeners/tcp.go:113 +0x3d
created by github.com/wind-c/comqtt/server/listeners.(*TCP).Serve
    /home/james/projects/web-mon/server/vendor/github.com/wind-c/comqtt/server/listeners/tcp.go:112 +0xea

The broker is started with

func startMqttBroker() *mqtt.Server {
    server := mqtt.NewServer(nil)
    tcp := listeners.NewTCP("tcp1", ":1883")
    err := server.AddListener(tcp, nil)
    if err != nil {
        log.Fatal(err)
    }
    go func() {
        err := server.Serve()
        if err != nil {
            log.Fatal(err)
        }
    }()
    return server
}
wind-c commented 1 year ago

The type of PacketID is uint16.

wind-c commented 1 year ago

It has been fixed in the 2.0 release.