From bcb01f2a11956b8d35cc4bcee4886a755944658e Mon Sep 17 00:00:00 2001 From: Albert Chu Date: Sat, 10 Aug 2024 07:58:01 -0700 Subject: [PATCH] kvs: correct code logic about what is an append Problem: In PR #2547, a fix was added into the KVS to deal with duplicate appends to a KVS entry. However, a corner case was left in the code. When an append is done to a KVS entry that does not exist, the append is treated like a normal insertion. This corner case should also be counted as an "append". Otherwise, duplicate appends could happen at the beginning of a KVS entry when it is created. Solution: Set the append flag to true when a KVS entry does not exist and the append is treated like an insert. Fixes #6207 --- src/modules/kvs/kvstxn.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/modules/kvs/kvstxn.c b/src/modules/kvs/kvstxn.c index 41c79c451140..3bd13ee6819d 100644 --- a/src/modules/kvs/kvstxn.c +++ b/src/modules/kvs/kvstxn.c @@ -495,6 +495,10 @@ static int kvstxn_append (kvstxn_t *kt, json_t *dirent, /* entry not found, treat like normal insertion */ if (treeobj_insert_entry (dir, final_name, dirent) < 0) return -1; + /* N.B. although this is an "insert", we still treat this as + * an "append". If we don't, the "append" could be issued + * twice, leading to duplicated data. See issue #6207. */ + (*append) = true; } else if (treeobj_is_valref (entry)) { char ref[BLOBREF_MAX_STRING_SIZE];