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

Added the code to handle panic while destroying the pubnub client in case pn.jobQueue is already closed #161

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions pubnub.go
Original file line number Diff line number Diff line change
Expand Up @@ -740,8 +740,20 @@ func (pn *PubNub) Destroy() {
pn.Config.Log.Println("calling RemoveAllListeners")
pn.subscriptionManager.RemoveAllListeners()
pn.Config.Log.Println("after RemoveAllListeners")
close(pn.jobQueue)
pn.Config.Log.Println("after close jobQueue")
// Check if jobQueue is already closed before attempting to close it
select {
case _, ok := <-pn.jobQueue:
if !ok {
pn.Config.Log.Println("jobQueue is already closed")
break
}
// If the channel is open, proceed to close it
close(pn.jobQueue)
pn.Config.Log.Println("after close jobQueue")
default:
// If the channel is closed, no action is needed
pn.Config.Log.Println("jobQueue is already closed")
}
pn.requestWorkers.Close()
pn.Config.Log.Println("after close requestWorkers")
pn.tokenManager.CleanUp()
Expand Down