server icon indicating copy to clipboard operation
server copied to clipboard

panic: runtime error: invalid memory address or nil pointer dereference

Open youmisun opened this issue 1 year ago • 2 comments

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

goroutine 52708 [running]: github.com/mochi-co/mqtt/server/internal/clients.(*Client).WritePacket(0xc000e63440, 0x0, 0x103, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...) /app/vendor/github.com/mochi-co/mqtt/server/internal/clients/clients.go:446 +0x94 github.com/mochi-co/mqtt/server.(*Server).writeClient(0xc000652460, 0xc000e63440, 0x0, 0x103, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...) /app/vendor/github.com/mochi-co/mqtt/server/server.go:413 +0x78 github.com/mochi-co/mqtt/server.(*Server).publishToSubscribers(0xc000652460, 0x5c, 0x10103, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...) /app/vendor/github.com/mochi-co/mqtt/server/server.go:662 +0x45e github.com/mochi-co/mqtt/server.(*Server).processPublish(0xc000652460, 0xc000b07560, 0x5c, 0x10103, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...) /app/vendor/github.com/mochi-co/mqtt/server/server.go:586 +0x258 github.com/mochi-co/mqtt/server.(*Server).processPacket(0xc000652460, 0xc000b07560, 0x5c, 0x10103, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...) /app/vendor/github.com/mochi-co/mqtt/server/server.go:436 +0x118 github.com/mochi-co/mqtt/server/internal/clients.(*Client).Read(0xc000b07560, 0xc002657848, 0xc001c96970, 0xf) /app/vendor/github.com/mochi-co/mqtt/server/internal/clients/clients.go:375 +0x1f5 github.com/mochi-co/mqtt/server.(*Server).EstablishConnection(0xc000652460, 0x177de10, 0x2, 0x19857e0, 0xc000645038, 0x1965aa8, 0xc000370550, 0x0, 0x0) /app/vendor/github.com/mochi-co/mqtt/server/server.go:342 +0x1071 github.com/mochi-co/mqtt/server/listeners.(*TCP).Serve.func1(0xc000370150, 0xc000492000, 0x19857e0, 0xc000645038) /app/vendor/github.com/mochi-co/mqtt/server/listeners/tcp.go:106 +0x66 created by github.com/mochi-co/mqtt/server/listeners.(*TCP).Serve /app/vendor/github.com/mochi-co/mqtt/server/listeners/tcp.go:105 +0x95

youmisun avatar Aug 02 '22 05:08 youmisun

Thank you I will look into why this might have happened!

mochi-co avatar Aug 16 '22 21:08 mochi-co

This may be related, triggered while stress testing:

mqtt-stresser -broker tcp://localhost:1883 -num-clients=2 -num-messages=10000

================== WARNING: DATA RACE Write at 0x00c00092e448 by goroutine 13263: github.com/mochi-co/mqtt/server/internal/clients.(*Client).ClearBuffers() /mochi-co/mqtt/server/internal/clients/clients.go:281 +0x6c github.com/mochi-co/mqtt/server.(*Server).EstablishConnection.func3() /mochi-co/mqtt/server/server.go:304 +0x34 runtime.deferreturn() /usr/local/go/src/runtime/panic.go:476 +0x30 github.com/mochi-co/mqtt/server.(*Server).EstablishConnection-fm() :1 +0x64 github.com/mochi-co/mqtt/server/listeners.(*TCP).Serve.func1() /mochi-co/mqtt/server/listeners/tcp.go:106 +0xa8

Previous read at 0x00c00092e448 by goroutine 11: github.com/mochi-co/mqtt/server/internal/clients.(*Client).WritePacket() /mochi-co/mqtt/server/internal/clients/clients.go:500 +0x304 github.com/mochi-co/mqtt/server.(*Server).ResendClientInflight() /mochi-co/mqtt/server/server.go:938 +0x2ec github.com/mochi-co/mqtt/server.(*Server).resendPendingInflights() /mochi-co/mqtt/server/server.go:1122 +0x94 github.com/mochi-co/mqtt/server.(*Server).eventLoop() /mochi-co/mqtt/server/server.go:220 +0x1c4 github.com/mochi-co/mqtt/server.(*Server).Serve.func1() /mochi-co/mqtt/server/server.go:199 +0x34

Goroutine 13263 (running) created at: github.com/mochi-co/mqtt/server/listeners.(*TCP).Serve() /mochi-co/mqtt/server/listeners/tcp.go:105 +0x154 github.com/mochi-co/mqtt/server/listeners.(*Listeners).Serve.func1() /mochi-co/mqtt/server/listeners/listeners.go:109 +0x90 github.com/mochi-co/mqtt/server/listeners.(*Listeners).Serve.func2() /mochi-co/mqtt/server/listeners/listeners.go:110 +0x44

Goroutine 11 (running) created at: github.com/mochi-co/mqtt/server.(*Server).Serve() /mochi-co/mqtt/server/server.go:199 +0xa8 main.main.func2() /mochi-co/mqtt/examples/tcp/main.go:45 +0x2c

mochi-co avatar Sep 02 '22 20:09 mochi-co

Resolved in v2.0.0

mochi-co avatar Dec 10 '22 22:12 mochi-co