summaryrefslogtreecommitdiffstats
path: root/app/channel.go
diff options
context:
space:
mode:
authorCorey Hulen <corey@hulen.com>2017-02-17 08:20:29 -0500
committerJoram Wilander <jwawilander@gmail.com>2017-02-17 08:20:29 -0500
commitda448cedc8329246e0a4bf027c161dcd15d29a36 (patch)
tree03289e1b071b83d9a6d94688a2873c5fea78f238 /app/channel.go
parent48b785aded359c98cf0008bd652a4437ea807cbd (diff)
downloadchat-da448cedc8329246e0a4bf027c161dcd15d29a36.tar.gz
chat-da448cedc8329246e0a4bf027c161dcd15d29a36.tar.bz2
chat-da448cedc8329246e0a4bf027c161dcd15d29a36.zip
Fix issue with Aurora read replica (#5448)
Diffstat (limited to 'app/channel.go')
-rw-r--r--app/channel.go30
1 files changed, 30 insertions, 0 deletions
diff --git a/app/channel.go b/app/channel.go
index 4d02817f6..347c106a8 100644
--- a/app/channel.go
+++ b/app/channel.go
@@ -7,6 +7,7 @@ import (
"fmt"
"net/http"
"strings"
+ "time"
l4g "github.com/alecthomas/log4go"
"github.com/mattermost/platform/model"
@@ -153,6 +154,8 @@ func CreateDirectChannel(userId string, otherUserId string) (*model.Channel, *mo
} else {
channel := result.Data.(*model.Channel)
+ WaitForChannelMembership(channel.Id, userId)
+
InvalidateCacheForUser(userId)
InvalidateCacheForUser(otherUserId)
@@ -164,6 +167,31 @@ func CreateDirectChannel(userId string, otherUserId string) (*model.Channel, *mo
}
}
+func WaitForChannelMembership(channelId string, userId string) {
+ if len(utils.Cfg.SqlSettings.DataSourceReplicas) > 0 {
+ now := model.GetMillis()
+
+ for model.GetMillis()-now < 12000 {
+
+ time.Sleep(100 * time.Millisecond)
+
+ result := <-Srv.Store.Channel().GetMember(channelId, userId)
+
+ // If the membership was found then return
+ if result.Err == nil {
+ return
+ }
+
+ // If we recieved a error but it wasn't a missing channel member then return
+ if result.Err.Id != store.MISSING_CHANNEL_MEMBER_ERROR {
+ return
+ }
+ }
+
+ l4g.Error("WaitForChannelMembership giving up channelId=%v userId=%v", channelId, userId)
+ }
+}
+
func UpdateChannel(channel *model.Channel) (*model.Channel, *model.AppError) {
if result := <-Srv.Store.Channel().Update(channel); result.Err != nil {
return nil, result.Err
@@ -327,6 +355,8 @@ func addUserToChannel(user *model.User, channel *model.Channel) (*model.ChannelM
return nil, model.NewLocAppError("AddUserToChannel", "api.channel.add_user.to.channel.failed.app_error", nil, "")
}
+ WaitForChannelMembership(channel.Id, user.Id)
+
InvalidateCacheForUser(user.Id)
InvalidateCacheForChannelMembers(channel.Id)