From 06f1d59b3fdb43b5d505faa418789ddd7b244726 Mon Sep 17 00:00:00 2001 From: Tyler Date: Thu, 4 May 2017 01:40:02 -0400 Subject: [PATCH] Fix concurrency issue with writes --- pubsub.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pubsub.go b/pubsub.go index 8f59b53..da98d0d 100644 --- a/pubsub.go +++ b/pubsub.go @@ -102,6 +102,9 @@ func (t *TwitchPubSub) Open() error { if len(t.SubscribedTopics) > 0 { return t.listen(t.SubscribedTopics) } else { + t.wsMutex.Lock() + defer t.wsMutex.Unlock() + t.LastPing = time.Now() return t.wsConn.WriteJSON(&twitchMessage{Type: Ping}) }