andreykaipov/goobs

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

Closed this issue · 3 comments

Vany commented

[signal SIGSEGV: segmentation violation code=0x2 addr=0x0 pc=0x100c7234c]

goroutine 37 [running]:
github.com/andreykaipov/goobs.(*Client).Disconnect(0x0)
/Users/vany/go/pkg/mod/github.com/andreykaipov/goobs@v0.12.1/client.go:89 +0x1c
github.com/vany/controlrake/src/obs.(*Obs).Init.func1()
/Users/vany/a/controlrake/src/obs/obs.go:61 +0x12c
created by github.com/vany/controlrake/src/obs.(*Obs).Init in goroutine 1
/Users/vany/a/controlrake/src/obs/obs.go:45 +0xe0

it is after obs was shuted down i called disconnect()
afriza commented

@Vany in my opinion, it seems to be some logic issue in your application. o.Client is nil when you call o.Client.Disconnect().

https://github.com/Vany/controlrake/blob/dc1d7b9a9ea6ba976555b3ed85ec50e0fb2125b8/src/obs/obs.go#L61

Hey @Vany, sorry for the late reply but unfortunately I can't reproduce this by disconnecting after OBS is already shut down.

The stack trace is interesting though. It's indicating this is the problem line. So either c.Client.Log or c.Client is nil, but this should be impossible if called after goobs.New() because that's all initialized here.

Like @afriza mentioned, I think you've got something strange happening in your initialization code there. Could you provide a minimal reproducible example?

I'm gonna close this out. I saw in the latest version of your code you have a nil check. I think that's a good way to go about it. I released a new major version v1.0.0 that includes some improvements to the disconnection logic as well as hiding any internal fields to make troubleshooting things like this easier in the future.