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) })