summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCorey Hulen <corey@hulen.com>2017-08-22 10:20:54 -0700
committerGitHub <noreply@github.com>2017-08-22 10:20:54 -0700
commitb0e367b19249e72748e719b7ff69671db3656e25 (patch)
treea0a53d33033f2830b7b53abbdb89ed8f2a8f6203
parent1ce079d2d04442fb91485e88cbda67ebf260a9e8 (diff)
downloadchat-b0e367b19249e72748e719b7ff69671db3656e25.tar.gz
chat-b0e367b19249e72748e719b7ff69671db3656e25.tar.bz2
chat-b0e367b19249e72748e719b7ff69671db3656e25.zip
Fixing race in update channel (#7269)
* Fixing race in update channel * Switching to struct copy
-rw-r--r--model/channel.go5
-rw-r--r--model/channel_test.go9
-rw-r--r--store/sql_channel_store.go2
3 files changed, 15 insertions, 1 deletions
diff --git a/model/channel.go b/model/channel.go
index 50d487557..48abd1070 100644
--- a/model/channel.go
+++ b/model/channel.go
@@ -53,6 +53,11 @@ type ChannelPatch struct {
Purpose *string `json:"purpose"`
}
+func (o *Channel) DeepCopy() *Channel {
+ copy := *o
+ return &copy
+}
+
func (o *Channel) ToJson() string {
b, err := json.Marshal(o)
if err != nil {
diff --git a/model/channel_test.go b/model/channel_test.go
index ee6a70b0d..ed6aed919 100644
--- a/model/channel_test.go
+++ b/model/channel_test.go
@@ -27,6 +27,15 @@ func TestChannelJson(t *testing.T) {
}
}
+func TestChannelCopy(t *testing.T) {
+ o := Channel{Id: NewId(), Name: NewId()}
+ ro := o.DeepCopy()
+
+ if o.Id != ro.Id {
+ t.Fatal("Ids do not match")
+ }
+}
+
func TestChannelPatch(t *testing.T) {
p := &ChannelPatch{Name: new(string), DisplayName: new(string), Header: new(string), Purpose: new(string)}
*p.Name = NewId()
diff --git a/store/sql_channel_store.go b/store/sql_channel_store.go
index db9c2c1f4..690b1c176 100644
--- a/store/sql_channel_store.go
+++ b/store/sql_channel_store.go
@@ -405,7 +405,7 @@ func (s SqlChannelStore) get(id string, master bool, allowFromCache bool) StoreC
if metrics != nil {
metrics.IncrementMemCacheHitCounter("Channel")
}
- result.Data = cacheItem.(*model.Channel)
+ result.Data = (cacheItem.(*model.Channel)).DeepCopy()
storeChannel <- result
close(storeChannel)
return