[MM-29295] Fix data race in app.CreatePost() (#15880)

* Fix data race

* Better naming

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
Claudio Costa
2020-10-27 20:11:38 +01:00
коммит произвёл GitHub
родитель 9cb704d537
Коммит 165c4d2dd1

Просмотреть файл

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