From 165c4d2dd194d9ac3014945b62a965dff525d693 Mon Sep 17 00:00:00 2001 From: Claudio Costa Date: Tue, 27 Oct 2020 20:11:38 +0100 Subject: [PATCH] [MM-29295] Fix data race in app.CreatePost() (#15880) * Fix data race * Better naming Co-authored-by: Mattermod --- app/post.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/post.go b/app/post.go index a2ccb7824e..f6810c9754 100644 --- a/app/post.go +++ b/app/post.go @@ -320,11 +320,13 @@ func (a *App) CreatePost(post *model.Post, channel *model.Channel, triggerWebhoo // might be duplicating requests. a.Srv().seenPendingPostIdsCache.SetWithExpiry(post.PendingPostId, rpost.Id, PENDING_POST_IDS_CACHE_TTL) + // We make a copy of the post for the plugin hook to avoid a race condition. + rPostCopy := rpost.Clone() if pluginsEnvironment := a.GetPluginsEnvironment(); pluginsEnvironment != nil { a.Srv().Go(func() { pluginContext := a.PluginContext() pluginsEnvironment.RunMultiPluginHook(func(hooks plugin.Hooks) bool { - hooks.MessageHasBeenPosted(pluginContext, rpost) + hooks.MessageHasBeenPosted(pluginContext, rPostCopy) return true }, plugin.MessageHasBeenPostedId) })