diff --git a/server/.golangci.yml b/server/.golangci.yml index f39a6175df..7d3fa2f05a 100644 --- a/server/.golangci.yml +++ b/server/.golangci.yml @@ -119,7 +119,6 @@ issues: channels/app/plugin_install.go|\ channels/app/plugin_signature_test.go|\ channels/app/plugin_test.go|\ - channels/app/post.go|\ channels/app/post_helpers_test.go|\ channels/app/post_test.go|\ channels/app/security_update_check.go|\ diff --git a/server/channels/app/post.go b/server/channels/app/post.go index 5b7d5b1124..e2169539e6 100644 --- a/server/channels/app/post.go +++ b/server/channels/app/post.go @@ -145,7 +145,9 @@ func (a *App) deduplicateCreatePost(rctx request.CTX, post *model.Post) (foundPo var postID string nErr := a.Srv().seenPendingPostIdsCache.Get(post.PendingPostId, &postID) if nErr == cache.ErrKeyNotFound { - a.Srv().seenPendingPostIdsCache.SetWithExpiry(post.PendingPostId, unknownPostId, PendingPostIDsCacheTTL) + if appErr := a.Srv().seenPendingPostIdsCache.SetWithExpiry(post.PendingPostId, unknownPostId, PendingPostIDsCacheTTL); appErr != nil { + return nil, model.NewAppError("deduplicateCreatePost", "api.post.deduplicate_create_post.cache_error", nil, "", http.StatusInternalServerError).Wrap(appErr) + } return nil, nil } @@ -193,11 +195,15 @@ func (a *App) CreatePost(c request.CTX, post *model.Post, channel *model.Channel } if err != nil { - a.Srv().seenPendingPostIdsCache.Remove(post.PendingPostId) + if appErr := a.Srv().seenPendingPostIdsCache.Remove(post.PendingPostId); appErr != nil { + err = model.NewAppError("CreatePost", "api.post.deduplicate_create_post.cache_error", nil, "", http.StatusInternalServerError).Wrap(appErr) + } return } - a.Srv().seenPendingPostIdsCache.SetWithExpiry(post.PendingPostId, savedPost.Id, PendingPostIDsCacheTTL) + if appErr := a.Srv().seenPendingPostIdsCache.SetWithExpiry(post.PendingPostId, savedPost.Id, PendingPostIDsCacheTTL); appErr != nil { + err = model.NewAppError("CreatePost", "api.post.deduplicate_create_post.cache_error", nil, "", http.StatusInternalServerError).Wrap(appErr) + } }() // Validate recipients counts in case it's not DM @@ -361,7 +367,9 @@ func (a *App) CreatePost(c request.CTX, post *model.Post, channel *model.Channel // Update the mapping from pending post id to the actual post id, for any clients that // might be duplicating requests. - a.Srv().seenPendingPostIdsCache.SetWithExpiry(post.PendingPostId, rpost.Id, PendingPostIDsCacheTTL) + if appErr := a.Srv().seenPendingPostIdsCache.SetWithExpiry(post.PendingPostId, rpost.Id, PendingPostIDsCacheTTL); appErr != nil { + return nil, model.NewAppError("CreatePost", "api.post.deduplicate_create_post.cache_error", nil, "", http.StatusInternalServerError).Wrap(appErr) + } if a.Metrics() != nil { a.Metrics().IncrementPostCreate() @@ -1536,7 +1544,9 @@ func (a *App) searchPostsInTeam(teamID string, userID string, paramsList []*mode posts.SortByCreateAt() - a.filterInaccessiblePosts(posts, filterPostOptions{assumeSortedCreatedAt: true}) + if appErr := a.filterInaccessiblePosts(posts, filterPostOptions{assumeSortedCreatedAt: true}); appErr != nil { + return nil, appErr + } return posts, nil } diff --git a/server/i18n/en.json b/server/i18n/en.json index 67d8c0c08c..9c034429b3 100644 --- a/server/i18n/en.json +++ b/server/i18n/en.json @@ -2520,6 +2520,10 @@ "id": "api.post.create_webhook_post.creating.app_error", "translation": "Error creating post." }, + { + "id": "api.post.deduplicate_create_post.cache_error", + "translation": "Failed to cache post after deduplicating a client repeating the same request." + }, { "id": "api.post.deduplicate_create_post.failed_to_get", "translation": "Failed to fetch original post after deduplicating a client repeating the same request."