Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Panic when immediately calling Destroy #159

Open
BSkin opened this issue Jan 4, 2024 · 1 comment
Open

Panic when immediately calling Destroy #159

BSkin opened this issue Jan 4, 2024 · 1 comment

Comments

@BSkin
Copy link

BSkin commented Jan 4, 2024

There are some cases where we want to publish messages before calling the Destroy function on the pubnub object, and other cases where there is nothing to publish and we call Destroy immediately.

This causes a panic on version github.com/pubnub/go/v7 v7.2.1, which is easily reproducible with a minimal setup

package main

import (
	pn "github.com/pubnub/go/v7"
)

func main() {
	config := pn.NewConfigWithUserId(pn.UserId("userid"))
	config.AuthKey = "xxxx"
	config.PublishKey = "yyyy"
	config.SubscribeKey = "zzzz"

	pubnub := pn.NewPubNub(config)
	// pubnub.GetClient()
	pubnub.Destroy()
}
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x5ec94e]

goroutine 1 [running]:
net/http.(*Client).transport(...)
	/usr/lib/go/src/net/http/client.go:201
net/http.(*Client).CloseIdleConnections(0xc0000a92c0?)
	/usr/lib/go/src/net/http/client.go:947 +0xe
github.com/pubnub/go/v7.(*PubNub).Destroy(0xc0000c4420)
	.../go/pkg/mod/github.com/pubnub/go/[email protected]/pubnub.go:748 +0x67f
main.main()
	.../projects/masv/misc/pubnub_panic_test/main.go:16 +0x13d

Calling GetClient() on the pubnub object before calling Destroy properly sets up the client/transport, which prevents the panic from ocurring.

Unless this is documented somewhere that I missed, I believe that pn.NewPubNub(config) should properly setup the client.

@dsnidr
Copy link

dsnidr commented Feb 5, 2024

I'm seeing the same issue. Has there been any movement on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants