Skip to content

Panic when immediately calling Destroy #159

@BSkin

Description

@BSkin

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/v7@v7.2.1/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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions