Repository navigation
[backport] Backport sweep for 9.2 - #5619
valkeyrie-ops[bot] wants to merge 36 commits into
Conversation
|
Important Review skippedBot user detected. To trigger a single review, invoke the
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## 9.2 #5619 +/- ##
==========================================
+ Coverage 81.63% 81.76% +0.13%
==========================================
Files 199 201 +2
Lines 105022 105326 +304
==========================================
+ Hits 85736 86124 +388
+ Misses 19286 19202 -84
🚀 New features to boost your workflow:
|
The agent's commits were made as valkeyrie-bot[bot], a name with no GitHub account behind it, and most had no DCO sign-off. Its own fixes and repair commits had none, and a backport kept only what its upstream commit carried: sometimes nothing, sometimes a sign-off under another email than its author's. The DCO check therefore fails on the sweep pull requests (valkey-io/valkey#5619, valkey-io/valkey#5499), on the CI-sweep pull requests (valkey-io/valkey#5441) and on the fixes opened into unstable (valkey-io/valkey#5437, valkey-io/valkey#5440, valkey-io/valkey#5443), and a maintainer has to override it. Every commit the agent makes is now committed and signed off by valkeyrie-ops[bot], the App that opens its pull requests. The identity and the sign-off line are in scripts/common/identity.py, and proc.set_commit_identity gives them to a clone. - A commit the agent writes (a CI fix, a sweep's repair commit, a revert, a release cut) has the App as its author. - A commit it cherry-picks (a backport, an upstream fix ported to a backport branch) keeps its author and its own sign-off, and gets the App's as its committer. The DCO check takes a sign-off from a commit's author or its committer. - An open sweep branch from before this is signed off once, the next time it is rebased. Other open pull requests keep their commits. The pull requests the CI-fix bot opens now say that their commit carries the bot's sign-off and that a maintainer adds their own before merging. Nothing checks for the maintainer's. The registry edit that onboards a release branch is unchanged: it is github-actions[bot]'s commit and is already signed off. Signed-off-by: Sarthak Aggarwal <sarthagg@amazon.com>
* Sign off every commit the agent makes as valkeyrie-ops The agent's commits were made as valkeyrie-bot[bot], a name with no GitHub account behind it, and most had no DCO sign-off. Its own fixes and repair commits had none, and a backport kept only what its upstream commit carried: sometimes nothing, sometimes a sign-off under another email than its author's. The DCO check therefore fails on the sweep pull requests (valkey-io/valkey#5619, valkey-io/valkey#5499), on the CI-sweep pull requests (valkey-io/valkey#5441) and on the fixes opened into unstable (valkey-io/valkey#5437, valkey-io/valkey#5440, valkey-io/valkey#5443), and a maintainer has to override it. Every commit the agent makes is now committed and signed off by valkeyrie-ops[bot], the App that opens its pull requests. The identity and the sign-off line are in scripts/common/identity.py, and proc.set_commit_identity gives them to a clone. - A commit the agent writes (a CI fix, a sweep's repair commit, a revert, a release cut) has the App as its author. - A commit it cherry-picks (a backport, an upstream fix ported to a backport branch) keeps its author and its own sign-off, and gets the App's as its committer. The DCO check takes a sign-off from a commit's author or its committer. - An open sweep branch from before this is signed off once, the next time it is rebased. Other open pull requests keep their commits. The pull requests the CI-fix bot opens now say that their commit carries the bot's sign-off and that a maintainer adds their own before merging. Nothing checks for the maintainer's. The registry edit that onboards a release branch is unchanged: it is github-actions[bot]'s commit and is already signed off. Signed-off-by: Sarthak Aggarwal <sarthagg@amazon.com> * Pass the App's identity with each commit command A sweep commits in the clone its validation builds and tests in, and git took the committer, and the name `commit -s` signs with, from that clone's config, set once after cloning. A test that rewrote the config changed whose commit and sign-off the next one was. Every git command that commits now gets the identity in its environment (proc.commit_env), which git reads before any config, and a clone is no longer given one. A cherry-pick, a rebase and an amend still keep the commit's author. A CI fix written before the sign-offs keeps its unsigned commit when its CI-sweep branch is rebuilt. The docs now say so. Signed-off-by: Sarthak Aggarwal <sarthagg@amazon.com> --------- Signed-off-by: Sarthak Aggarwal <sarthagg@amazon.com>
|
Automatic follow-up on this backport's CI. No fix for |
|
Automatic follow-up on this backport's CI. No fix for |
|
Automatic follow-up on this backport's CI. A fix for Proposed patchdiff --git a/tests/unit/memefficiency.tcl b/tests/unit/memefficiency.tcl
index dea3b0330..d32195ce3 100644
--- a/tests/unit/memefficiency.tcl
+++ b/tests/unit/memefficiency.tcl
@@ -714,7 +714,7 @@ run_solo {defrag} {
assert_equal [list unsubscribe $chan 0] [$listener read]
assert_equal [list $chan 0] [r pubsub numsub $chan]
$listener close
- }
+ } {0} {logreqres:skip} ;# copy avoidance encodes the reply buffers, which breaks req-res logging
}
proc test_tracking_table {type} { |
|
Automatic follow-up on the scheduled test run of No fix for |
…4889) This is a regression from #4019, first released in 9.2.0-rc1. A user whose ACL only allows `db=1` can no longer run `MULTI` / `SELECT 1` / `SET x 1` / `EXEC` from a connection that starts in DB 0, which works in 9.1. `EXEC` now fails with `EXECABORT ... NOPERM No permissions to access database`. #4019 gave `EXEC` key-specs for its new condition keys, so the ACL check treats every `EXEC` as a keyed command and requires access to the pre-transaction DB, even a bare `EXEC` that reads nothing from it. Each queued command is still checked against its own DB when it runs, so this only applies the DB check to `EXEC` when it has arguments. <details> <summary>AI generated details</summary> ## Problem `ACLSelectorCheckCmd` denies any command for which `shouldRestrictCmd()` is true when the selector cannot access `dbid` (`src/acl.c:2296`). `shouldRestrictCmd()` includes `doesCommandHaveKeys(cmd)`. Before 0adf657 (#4019), `EXEC` had no key-specs and only the `SLOW` and `TRANSACTION` categories, so it was never DB-restricted. #4019 added a key-spec for the `IFEQ`/`IFNE`/`NX`/`XX` keys, and changed `ACLCheckAllPerm` to pass `c->db->id` for `EXEC` (`src/acl.c:2541`). That is the DB the client was in before `MULTI`, because queued `SELECT`s have not run yet. That DB is correct for condition keys, since `checkExecConditions` reads them from `c->db` (`src/multi.c:286`). It is wrong for a bare `EXEC`, which reads nothing there. The queued commands are re-checked against their own DB as they run (`src/multi.c:380`). The existing #4019 test passes a condition key, so it never checks an `EXEC` without one. Affected: 9.2.0-rc1 and the `9.2` branch. In 9.1 and earlier, `exec.json` has no key-specs and the same transaction succeeds. Behavior for user `db=1 +@ALL ~*`, connection starting in DB 0: | Input | Before | After | |---|---|---| | `MULTI` / `SELECT 1` / `SET x 1` / `EXEC` | `EXECABORT ... NOPERM ... database` | `OK OK` | | `MULTI` / `EXEC` | `EXECABORT ... NOPERM ... database` | empty array | | `EXEC` without `MULTI` | `EXECABORT ... NOPERM ... database` | `ERR EXEC without MULTI` | | `MULTI` / `SELECT 1` / `SET x 1` / `EXEC XX x` | `EXECABORT ... NOPERM ... database` | unchanged | | `MULTI` / `SELECT 1` / `SET x 1` / `EXEC foo` (malformed) | `EXECABORT ... NOPERM ... database` | unchanged | | `SELECT 1` / `MULTI` / `SET x 1` / `EXEC` | `OK` | unchanged | With selectors `(db=1 +@ALL ~*) (db=0 +@ALL ~public*)`, `EXEC IFEQ secret v` from DB 0 is still `NOPERM ... key`. ## Fix Skip the active-DB check only when the command is `EXEC` and `argc == 1`. With any arguments, `EXEC` stays restricted to the active DB, including malformed ones, which keeps the base behavior. ## Alternative considered Only DB-restrict `NO_MANDATORY_KEYS` commands when the invocation actually has keys. That would also lift the DB restriction on `EVAL`, `EVALSHA`, and `FCALL` with zero keys, which are DB-restricted today. That is an ACL change to commands this regression does not touch, and it needs its own review. ## Testing New test in `tests/unit/acl-v2.tcl`. It also checks that `EXEC XX <key>` from DB 0 is still denied. With only the `src/acl.c` hunk reverted: ``` [ok]: EXEC conditions require read permission (4 ms) [ok]: EXEC condition keys check permissions on the active database (2 ms) [exception]: Executing test client: EXECABORT Transaction discarded because of: NOPERM No permissions to access database. in valkey::__dispatch__ at tests/support/valkey.tcl:116 in $r2 at tests/unit/acl-v2.tcl:169 ``` Dropping the `argc == 1` guard, so that every `EXEC` skips the check, fails both this test and the existing #4019 test: ``` [err]: EXEC condition keys check permissions on the active database in tests/unit/acl-v2.tcl Expected '' to match '*NOPERM*key*' [err]: EXEC without conditions is not restricted to the active database in tests/unit/acl-v2.tcl Expected '' to match '*NOPERM*database*' ``` Based on upstream/unstable `8f67ab136`, so the base branch here is `upstream-unstable-8f67ab136`. </details> This was generated by AI but verified, with love, by a human. --------- Signed-off-by: Madelyn Olson <madelyneolson@gmail.com> Backport-Source-PR: 4889 Signed-off-by: valkeyrie-ops[bot] <284117741+valkeyrie-ops[bot]@users.noreply.github.com>
When SET has GET and no expiry, the primary propagates it with every argument after the value that spells GET removed. The IFEQ/IFNE comparison value is free-form, so a comparison value of `GET` was removed too, and replicas and the AOF then diverge from the primary. The fix keeps the argument that is the comparison value. Signed-off-by: Madelyn Olson <madelyneolson@gmail.com> Backport-Source-PR: 5090 Signed-off-by: valkeyrie-ops[bot] <284117741+valkeyrie-ops[bot]@users.noreply.github.com>
…4971) With reply copy avoidance, a queued SUBSCRIBE/UNSUBSCRIBE reply keeps a reference to a RAW channel object until it is written. A subscriber that stops reading keeps that reference, so the next pubsub defrag pass aborts on the refcount assert in defragPubsubScanCallback. Only move the channel when its refcount is exactly subscribers + 1, and skip it for this cycle otherwise. The assert becomes >=, so a missing reference still aborts. This also makes channel name defrag work again. Since the switch to hashtable, the callback used activeDefragStringOb(), which skips any object with refcount != 1, so channels were never moved. The old object is now freed only after every client's reference points at the new one, because the loop looks clients up by the old pointer. --------- Signed-off-by: Yechiel Merzbach <yechielm@amazon.com> Co-authored-by: Ran Shidlansik <ranshid@amazon.com> Backport-Source-PR: 4971 Signed-off-by: valkeyrie-ops[bot] <284117741+valkeyrie-ops[bot]@users.noreply.github.com>
…ue (#5476) In check mode, rdbLoadCheckModuleValue() walks a module value's opcodes until RDB_MODULE_OPCODE_EOF, but the opcode chain had no final branch. An RDB cut between two fields inside a module value made rdbLoadLen() return RDB_LENERR forever, so valkey-check-rdb, and server startup on a truncated RDB, hung at 100% CPU. Report a short read on RDB_LENERR and corruption on any other unknown opcode, and stop the loop. Backport-Source-PR: 5476 Signed-off-by: valkeyrie-ops[bot] <284117741+valkeyrie-ops[bot]@users.noreply.github.com>
The delete hook ran inside the `ref != NULL` branch of dbGenericDeleteWithDictIndex(), so only a delete that actually removed something was charged. Two client-issued DEL/UNLINK were therefore invisible: - Delete miss: the key is not there, so the hook never ran. - The key is logically expired: the removal goes through the expire path, and delGenericCommand() skips the DB_FLAG_KEY_DELETED delete. Both are still a client operating on the key name, which is the rule lookupKey() already applies to misses -- and what makes create/delete churn keys show up at all. Charge the miss case in dbGenericDeleteWithDictIndex() and the expire case in delGenericCommand(). hotkeys was introduced in #3708. Also with this change, a miss scenario for GETDEL will be counted twice. This is an area for future optimization: we could skip the DEL operation when the GET returns null, thereby avoiding an extra lookup. --------- Signed-off-by: Binbin <binloveplay1314@qq.com> Backport-Source-PR: 5079 Signed-off-by: valkeyrie-ops[bot] <284117741+valkeyrie-ops[bot]@users.noreply.github.com>
`SCRIPT DEBUG YES/SYNC` set the Lua engine's global `ldb.active` flag at enable time. From then on, every EVAL from any client ran under the debugger, and the debugger read its commands from the connection that last ran SCRIPT DEBUG. One client could then step through another client's script and run commands with that client's permissions. Only mark the Lua debugger active when the debugging client's own session starts (ldbStart() already does this), and bind each session to the connection of the client running the script instead of the last client that enabled debugging. --------- Signed-off-by: Yana Molodetsky <yamolodu@amazon.com> Co-authored-by: Ran Shidlansik <ranshid@amazon.com> Backport-Source-PR: 5596 Signed-off-by: valkeyrie-ops[bot] <284117741+valkeyrie-ops[bot]@users.noreply.github.com>
A replica with `repl-diskless-load swapdb` that full syncs while its primary is importing a slot via `CLUSTER MIGRATESLOTS` aborts on `kvstore.c:955`. The swapdb load keeps the old dataset in `server.db` and loads into a temporary db, but loading the RDB's slot import marked the slots as importing in `server.db`, which usually still holds keys in those slots. This marks the db being loaded instead, and stops the replica from failing the import it just loaded when it attaches to the new primary after the swap. Signed-off-by: Madelyn Olson <madelyneolson@gmail.com> Backport-Source-PR: 5143 Signed-off-by: valkeyrie-ops[bot] <284117741+valkeyrie-ops[bot]@users.noreply.github.com>
`ds.maxlen` is a `size_t`, but `sdscatfmt`'s `%U` expects an `unsigned long long`. On a 32-bit build `size_t` is 4 bytes, so the debugger's `maxlen` replies read 4 bytes of stack garbage and print a wrong value (e.g. "truncated at 6595234844957999164 bytes"). Cast to `unsigned long long` at both `%U` sites, matching the convention in `src/networking.c`. Fixes #5681 Signed-off-by: Yana Molodetsky <yamolodu@amazon.com> Backport-Source-PR: 5684 Signed-off-by: valkeyrie-ops[bot] <284117741+valkeyrie-ops[bot]@users.noreply.github.com>
### Problem With hot-key detection on, a cluster failover stalls every node in the cluster. `clusterDelSlot()` purged hot-key state for its slot. Each purge walks the whole top-k summary and hashes every key name in it. A failover reassigns every slot of the shard, and every node runs that reassignment slot by slot: the promoted replica claims the slots, and all other nodes learn of it through gossip. So each node scanned its summary up to 16,384 times on the main thread. This includes nodes in other shards that hold no entries for those slots. A failover also moves no keys, so the purge discarded valid data on every node of the shard. ### Change Purge only when a slot leaves this node's shard. `clusterDelSlot()` no longer purges, because it only knows the old owner. The callers that know the new owner purge only when the slot leaves this node's shard: - `clusterUpdateSlotsConfigWith()` and `CLUSTER SETSLOT <slot> NODE` purge only when the slot moves out of this node's shard. - A slot this node was importing that is then reassigned to a third shard is also purged in `clusterUpdateSlotsConfigWith()`. The per-reassignment helper cannot see it (the previous owner is the import source, in another shard), so it is purged where the abandoned importing state is cleared, guarded so an import finalized within this shard keeps its entries. - `CLUSTER DELSLOTS` purges each slot it unassigns. - `CLUSTER FLUSHSLOTS` now purges everything, as `CLUSTER RESET` already did. In a failover no slot changes shard, so no node purges or scans anything: `HOTKEYS GET` keeps its data on the promoted replica, its siblings and the demoted primary. No config changes, and recording a key access is unchanged. Known gaps (tolerated, the same tolerance the design already accepts for RENAME/MOVE): a shard-mate primary that announces it joined another shard as a replica leaves stale entries on its former replicas until they age out, at most two windows. Likewise, `CLUSTER FORGET` of a node whose slot this node was importing leaves the slot unassigned without purging; the operator has to reassign it anyway, and that path purges correctly. ### Testing New `tests/unit/cluster/hotkeys.tcl`: - After `CLUSTER FAILOVER`, the promoted, sibling and demoted nodes all keep their hot-key entries. Fails on `unstable`. - After `SETSLOT` to another shard, the moved slot's entries are gone and other slots' entries are kept. - An importing node drops the moved slot's entries when a third shard claims it, and keeps another slot's entries. ### Backport 9.2 has the same unconditional purge in `clusterDelSlot()` and the same call sites; the patch applies cleanly there. Hot-key detection was added in #3708. --------- Signed-off-by: Alon Arenberg <alonare@amazon.com> Backport-Source-PR: 5660 Signed-off-by: valkeyrie-ops[bot] <284117741+valkeyrie-ops[bot]@users.noreply.github.com>
57c6695 to
5e075c7
Compare
Followup for #5452 An older version could save a replicaof cycle (A -> B -> A) to nodes.conf from stale gossip. A later replica claim naming a node in the cycle as its primary then makes clusterNodeGetPrimary() loop forever. The file alone can't tell which link is stale, so fail to start with a corrupted config error. Signed-off-by: Bara' Hasheesh <bara.hasheesh@gmail.com> Backport-Source-PR: 5556 Signed-off-by: valkeyrie-ops[bot] <284117741+valkeyrie-ops[bot]@users.noreply.github.com>
## Problem `rewriteAppendOnlyFileRio()` releases `kvs_it` at the end of each db without clearing it. When a write error lands on the `SELECT` of a later non-empty db, `goto werr` runs before `kvs_it` is reassigned, so the error path releases the previous db's iterator a second time (use-after-free and double free in the AOF rewrite child). This path is only used when `aof-use-rdb-preamble` is `no`. The rewrite fails either way and the old AOF is kept, but the child runs on a corrupted heap and can crash instead of exiting with a write error. The bug was introduced by 0270abd (redis/redis#11695). It is in every Valkey release since 8.0.0. ## Fix The fix sets `kvs_it = NULL` after each release, as the loop did before 0270abd. Signed-off-by: Bara' Hasheesh <bara.hasheesh@gmail.com> Backport-Source-PR: 5584 Signed-off-by: valkeyrie-ops[bot] <284117741+valkeyrie-ops[bot]@users.noreply.github.com>
Signed-off-by: valkeyrie-ops[bot] <284117741+valkeyrie-ops[bot]@users.noreply.github.com>
## Summary Prevent 32-bit length overflow when constructing Valkey cluster module messages. ## Problem `createModuleMsgBlock()` calculates the serialized message length using `uint32_t`, while `createClusterMsgSendBlock()` adds the allocation prefix using the same width. For sufficiently large module payload lengths, the allocation-size calculation can wrap, causing the allocated buffer to be smaller than the space required for the message. The related Pub/Sub length-validation issue was addressed in #5030. This PR applies corresponding validation to the cluster module-message path. ## Changes - Add `clusterModuleMessageLengthValid()` to validate the payload against the complete cluster send-block allocation size. - Use the normal cluster-message header as a conservative upper bound, protecting both normal and lightweight message formats. - Reject oversized payloads before allocating, copying, or broadcasting messages. - Propagate rejection through the existing module API error path without changing the public API signature. - Document the additional error condition. - Add boundary regression tests and a module API integration test verifying safe rejection without sending a message. ## Testing - [x] Build Valkey successfully. - [x] Run `./runtest --single unit/moduleapi/cluster`. - [] Run `ClusterModuleTest.*` GoogleTest cases in CI. - [x] Confirm existing cluster-module message tests continue to pass. The oversized-payload regression uses a synthetic length and a small buffer. It does not allocate a multi-gigabyte payload. ### Local validation ./runtest --single unit/moduleapi/cluster — 50 passed, 0 failed. Memory-leak check passed. The GoogleTest arithmetic boundary cases and broader regression suite remain pending CI validation. ## Scope This is a narrowly scoped correctness fix. It does not change the cluster wire protocol, modify normal message serialization, or introduce a new public API. The issue was discussed privately with the Valkey security maintainers, who confirmed that the affected module API operates within Valkey's trusted-module boundary and recommended a public bug-fix PR against `unstable`. --------- Signed-off-by: SHUVA JYOTI KAR <shuva.jyoti.kar.87@gmail.com> Signed-off-by: SHUVA JYOTI KAR <33064034+shuvajyotikar13@users.noreply.github.com> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Backport-Source-PR: 5269 Signed-off-by: valkeyrie-ops[bot] <284117741+valkeyrie-ops[bot]@users.noreply.github.com>
Clamp used_memory_dataset (used_memory - used_memory_overhead) at 0 instead of letting the size_t subtraction wrap when the overhead is larger. Backport-Source-PR: 5644 Signed-off-by: valkeyrie-ops[bot] <284117741+valkeyrie-ops[bot]@users.noreply.github.com>
…B IDs (#5471) `valkey-check-rdb` starts with `selected_dbid = -1`. With `--stats`, a key that comes before any `SELECTDB` opcode makes `computeDatasetProfile()` index `rdbstate.stats[type + (-1) * OBJ_TYPE_MAX]`, before the start of the array, and crash. The server loads such keys into DB 0, so the checker now starts from DB 0 too. The DB ID read from `SELECTDB` is a 64-bit length stored in an `int`, and `(databases + 1) * OBJ_TYPE_MAX` is computed as an `int`. `SELECTDB 4294967295` sets `selected_dbid` back to -1, and IDs near `INT_MAX` overflow the size computation. IDs above `INT_MAX` are now reported as "Invalid DB ID", and with `--stats`, IDs from `INT_MAX / OBJ_TYPE_MAX` on are reported as too large for `--stats`. Both problems came with the RDB analysis reports (#1743), so they are in every release since 9.0.0. Backport-Source-PR: 5471 Signed-off-by: valkeyrie-ops[bot] <284117741+valkeyrie-ops[bot]@users.noreply.github.com>
…2933) The node ids returned by `ValkeyModule_GetClusterNodesList` are not null terminated, but fixed-length buffers. When these are passed to `ValkeyModule_GetClusterNodeInfo`, which until now required the node id to be null terminated, the node lookup failed or potentially caused undefined behavior when `strlen` read outside of allocated memory. This error can be seen in the example module hellocluster.c included in this repo. This commit changes `ValkeyModule_GetClusterNodeInfo` and `ValkeyModule_GetClusterNodeInfoForClient` to assumes the node id to be exactly 40 bytes long and does not require it to be null terminated. It's not a breaking change, since passing a valid null-terminated node id still works as expected. --------- Signed-off-by: Deepak Nandihalli <deepakrn@users.noreply.github.com> Signed-off-by: Deepak Nandihalli <deepak.nandihalli@gmail.com> Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> Co-authored-by: Viktor Söderqvist <viktor.soderqvist@est.tech> Backport-Source-PR: 2933 Signed-off-by: valkeyrie-ops[bot] <284117741+valkeyrie-ops[bot]@users.noreply.github.com>
Follow-up to #4060. `ioThreadWriteToClient()` stores `io_last_written` and then sets `io_write_state = CLIENT_COMPLETED_IO`. #3324 removed the release fence between the two stores. The main thread reads `io_write_state` with a plain load and takes an acquire only when it dequeues the completion from the outbox. `trimReplyUnusedTailSpace()` and the `setDeferredReply()` merges run on the main thread while a write completion is published but not yet dequeued. #4060 lets them mutate reply blocks in `CLIENT_COMPLETED_IO` when the bookmark pointer does not match. On a weakly ordered CPU (aarch64), the main thread can see `CLIENT_COMPLETED_IO` with the previous `io_last_written`, pass the pointer check, and reallocate the block the IO thread just bookmarked. If the allocator reuses that address for the next reply block, the stale `data_len` skips it: the iovec is empty, the write is zero bytes, and the write handler is re-armed forever. If the bookmark matches no block, `_postWriteToClient()` frees every pending block as written and the client loses whole replies. The stream stays valid RESP, shifted by the lost replies. The trim and both merges are now allowed only in `CLIENT_IDLE`, which the main thread sets after dequeuing the completion (release/acquire ordered), so the bookmark is visible by then. The pointer check stays, because a partial main-thread write leaves a live bookmark in `CLIENT_IDLE`. The release fence before both `CLIENT_COMPLETED_IO` stores is restored, and `cur_tid` is stored before it. `waitForClientIO()` relies on that fence, and `ioThreadAccept()` already has it. While a completion is queued the trim is skipped, so the deferred length goes into a new reply node. Tests refuse the trim and both merges in `CLIENT_PENDING_IO` and `CLIENT_COMPLETED_IO`. `TestStaleBookmarkSurvivesReorderedCompletion` replays the reordered completion deterministically and fails with the old guard. --------- Signed-off-by: Lior Malovani <liormal@amazon.com> Co-authored-by: Lior Malovani <liormal@amazon.com> Backport-Source-PR: 5669 Signed-off-by: valkeyrie-ops[bot] <284117741+valkeyrie-ops[bot]@users.noreply.github.com>
…OFF (#5682) On $ENDOFF, dualChannelReplHandleEndOffsetResponse() starts the PSYNC handshake on the main link with dualChannelSetupMainConnForPsync(). If a write on the main link fails there, that function calls cancelReplicationHandshake(), which aborts the whole dual channel sync: the RDB channel is closed, repl_rdb_transfer_s is NULL and repl_rdb_channel_state is NONE. The caller then set a read handler on the NULL repl_rdb_transfer_s and the replica crashed with SIGSEGV. Return C_RETRY when the RDB channel state is NONE after the main channel setup. C_ERR cannot be used: the error path would abort the sync a second time and replicationAbortDualChannelSyncTransfer() asserts that a sync is in progress. Add an integration test with a fake primary that resets the main link after +DUALCHANNELSYNC and then sends a valid $ENDOFF on the RDB channel. --------- Signed-off-by: Eran Liberty <eran.liberty@gmail.com> Co-authored-by: valkey-review-bot[bot] <282604435+valkey-review-bot[bot]@users.noreply.github.com> Co-authored-by: Ran Shidlansik <ranshid@amazon.com> Backport-Source-PR: 5682 Signed-off-by: valkeyrie-ops[bot] <284117741+valkeyrie-ops[bot]@users.noreply.github.com>
Sanitize CR/LF in FUNCTION LIST's error reply for an invalid argument, so it can't break the RESP stream. Backport-Source-PR: 5369 Signed-off-by: valkeyrie-ops[bot] <284117741+valkeyrie-ops[bot]@users.noreply.github.com>
SWAPDB changes what clients read from both databases, but tracking clients get no invalidation and keep stale cached values. Send the same invalidation FLUSHDB does, to all tracking clients, since the tracking table doesn't store a key's database. --------- Signed-off-by: Kyuwon Jeong <jkw5033@gmail.com> Backport-Source-PR: 5690 Signed-off-by: valkeyrie-ops[bot] <284117741+valkeyrie-ops[bot]@users.noreply.github.com>
…5611) Fixes #5608. `lookupStringForBitCommand()` creates or zero-pads the string before the BITFIELD ops run, but `dirty` was only turned into `changes` inside the branch that actually writes. If every write fails with `OVERFLOW FAIL`, `changes` stays 0, so nothing is propagated and the key exists on the primary but not on the replica or in the AOF. This counts the creation/growth as one change in that case, the same way SETBIT treats `dirty`. The command is propagated as is, and the replica ends up with the same zero-padded string. Side effects: a fully rejected BITFIELD that creates or grows the key now behaves like SETBIT does. It fires the `setbit` keyspace event, invalidates WATCH and client tracking on the key, and bumps `dirty`. Tests in `tests/unit/bitfield.tcl`: the replication block covers a new key and a grown key, plus a WATCH test (EXEC used to return PONG there, now nil), and a new `appendonly yes` block checks the created key survives `DEBUG LOADAOF`. All three fail without the bitops.c change and pass with it: ``` ./runtest --single unit/bitfield ``` `unit/bitops` and `unit/pubsub` also pass. --------- Signed-off-by: xhon-pelushi <xhon@pelushi.com> Backport-Source-PR: 5611 Signed-off-by: valkeyrie-ops[bot] <284117741+valkeyrie-ops[bot]@users.noreply.github.com>
… BGSAVE (#4941) Fixes #4938. With forkless BGSAVE, `MOVE` or `COPY` of a key that was created (or recreated) after the save started expedited that key into the snapshot. A new key then appeared in the RDB even though it did not exist at BGSAVE time, and a recreated key was saved twice, so the RDB would not load. `expediteSingleKeyWithoutOptimization` now skips entries whose `iterator_epoch` is newer than the consistent iterator's modification id, since they are not part of the snapshot. Added tests in `tests/integration/rdb.tcl` for a new key MOVE, a recreated key MOVE and a recreated key COPY. They fail on the unfixed source and pass with the change. Signed-off-by: drakeo338 <paranoyouz@gmail.com> Backport-Source-PR: 4941 Signed-off-by: valkeyrie-ops[bot] <284117741+valkeyrie-ops[bot]@users.noreply.github.com>
Signed-off-by: valkeyrie-ops[bot] <284117741+valkeyrie-ops[bot]@users.noreply.github.com>
Fixes #5610 valkey-check-rdb didn't know about `RDB_OPCODE_UPDATE` (242), so a dump.rdb written by a replica after a forkless sync (with `repl-diskless-load disabled`) was reported as `Invalid object type: 242` even though the server loads it fine. This adds a case that parses the embedded RESP command with `parseRespCommandFromReader`, same as `rdbLoad`, and skips it. Like `rdbLoad` it's only accepted for RDB version 81+, older files still fail. I made `rdbRioReader` / `rdbRioReadLine` non-static so the checker can reuse them instead of copying them. Added two tests to `integration/valkey-check-rdb` with a hand-built RDB containing a `SET k v` inline command (one at version 81, one at an older version). Also ran the repro from the issue locally: the replica's dump.rdb had 200 inline commands, check-rdb rejected it before and says OK now. --------- Signed-off-by: Dean Chen <862469039@qq.com> Backport-Source-PR: 5617 Signed-off-by: valkeyrie-ops[bot] <284117741+valkeyrie-ops[bot]@users.noreply.github.com>
Fixes #4935 ## Summary - AOF rewrite and `CLUSTER MIGRATESLOTS` rebuild consumer-group PELs as `XCLAIM FORCE JUSTID`. That command skipped IDs whose stream entry was already `XDEL`'d / trimmed, so pending ownership and delivery counts diverged from the source. - Keep the live XCLAIM cleanup (`nack != NULL` still drops a dangling PEL entry). Only an obeyed `FORCE JUSTID` with an empty PEL (AOF client, slot import, replica) may recreate the NACK. Signed-off-by: quanyeyang <quanyemostima@gmail.com> Backport-Source-PR: 4973 Signed-off-by: valkeyrie-ops[bot] <284117741+valkeyrie-ops[bot]@users.noreply.github.com>
If a module blocks a client on keys whose slots differ from the command's slot, the blocked client is later checked by clientsCronHandleTimeout(), which calls clusterRedirectBlockedClientIfNeeded(). There it hits the slot == c->slot assertion (added in #2165), since we do not allow cross-slot commands, and the server aborts. A module can reach this through incorrect use of the API. Even though it is a misuse, it should not be able to crash the server, so reject it in moduleBlockClient() by checking each key against c->slot and reply with an error instead of blocking. Modules that set VALKEYMODULE_CLUSTER_FLAG_NO_REDIRECTION manage key distribution themselves, so skip the validation for them, including the redirect check in clusterRedirectBlockedClientIfNeeded(). This adds one more error path that aborts after the blocked handle has been allocated. Such paths must reset bc->client to NULL, otherwise a later VM_UnblockClient() dereferences will crash the server. Only the Lua/MULTI path did this; apply the same to the other paths as well. Detached handles from key-blocking calls must also be releasable with VM_UnblockClient() even when no timeout callback was provided; otherwise they leak. Signed-off-by: Binbin <binloveplay1314@qq.com> Backport-Source-PR: 4541 Signed-off-by: valkeyrie-ops[bot] <284117741+valkeyrie-ops[bot]@users.noreply.github.com>
A replica that still cannot reach its primary can get that primary voted out after a partition heals, even though every other primary reaches it again. This needs a first election that failed while the primary was cut off, followed by a retry. The primary becomes a replica of the winner and loses the writes the winner had not received. Voters refuse a replica whose primary they see as up, unless the vote request carries FORCEACK, a flag that skips that check. #2227 added it so the best ranked replica can start its first election before the FAIL (failed) mark reaches the voters, but the replica also sends it on every retry. The other primaries clear the mark once it is older than twice the cluster node timeout and they reach the primary again. The replica cannot, so its retry, at least four node timeouts after the first election, wins their votes. Now the replica sends FORCEACK only while its FAIL mark is no older than twice the cluster node timeout, the age at which primaries clear it. The age restarts whenever the replica flags the primary again. The first election after a FAIL and manual failover are unchanged. A retry after an expired election always starts later than that, whatever the node timeout, so the primaries judge it by their own view. Only the replica knows how old its FAIL is, so the check lives there. Fixes #5403 Signed-off-by: 1fanwang <1fannnw@gmail.com> Backport-Source-PR: 5446 Signed-off-by: valkeyrie-ops[bot] <284117741+valkeyrie-ops[bot]@users.noreply.github.com>
Apple ARM64 uses 53-bit precision for long doble. Formatting the integer result through long double can round large integers on a platform with insufficient precision. Signed-off-by: Masahiro Ide <masahiro.ide@lycorp.co.jp> Backport-Source-PR: 5511 Signed-off-by: valkeyrie-ops[bot] <284117741+valkeyrie-ops[bot]@users.noreply.github.com>
Follow-up to #5669, as suggested in its review. `clientHasPendingReplies()` reads a replica's compression state (`out_buf`, `out_buf_pos`) whenever `io_write_state != CLIENT_PENDING_IO`. In `CLIENT_COMPLETED_IO` the main thread has not dequeued the IO completion yet, and the dequeue is where it gets acquire ordering. On a weakly ordered CPU (aarch64) it can see the new state before the IO thread's writes to the compression buffer, including a buffer that `sdsMakeRoomFor()` reallocated. The read now requires `CLIENT_IDLE`, which the main thread sets after the dequeue. `processClientIOWriteDone()` re-checks pending replies at that point, so no write event is lost. `getClientMemoryUsage()` keeps its `!= CLIENT_PENDING_IO` check. It sees `CLIENT_COMPLETED_IO` only through `catClientInfoString()`, which calls `waitForClientIO()` first. Its acquire fence pairs with the release that #5669 restored before the `CLIENT_COMPLETED_IO` store, so that read is ordered, and requiring `CLIENT_IDLE` there would only drop the staging buffer from `tot-mem` while a completion is queued. `TestReplicaCompressionStateIoGates` checks both functions in each write state and fails if the pending-replies check goes back to `!= CLIENT_PENDING_IO`. --------- Signed-off-by: Lior Malovani <liormal@amazon.com> Co-authored-by: Lior Malovani <liormal@amazon.com> Backport-Source-PR: 5689 Signed-off-by: valkeyrie-ops[bot] <284117741+valkeyrie-ops[bot]@users.noreply.github.com>
…5713) ## Fix crash in `VM_GetClientInfoById` for a client without a connection ### Problem A module command that asks for information about its own caller crashes the server when it runs from a script, a function or `VM_Call`. A typical case is an audit or rate-limiting module that logs or limits by the caller's address: ```c int AuditSet(ValkeyModuleCtx *ctx, ValkeyModuleString **argv, int argc) { ValkeyModuleClientInfo ci = VALKEYMODULE_CLIENTINFO_INITIALIZER_V1; ValkeyModule_GetClientInfoById(&ci, ValkeyModule_GetClientId(ctx)); log_access(ci.addr, ci.port, argv[1]); ... } ``` `AUDIT.SET k v` from a normal client works, but the following crashes with SIGSEGV: ``` EVAL "return server.call('AUDIT.SET', KEYS[1], ARGV[1])" 1 k v ``` Inside the script the command runs through the script's fake client, which has no connection, and `call()` makes it `server.executing_client`. `VM_GetClientInfoById()` returns `server.executing_client` when the id matches, and `modulePopulateClientInfoStructure()` then dereferences `client->conn` for the TLS flag and the peer address. ### Fix `modulePopulateClientInfoStructure()` skips the TLS flag and the peer address and port when the client has no connection. The structure is zeroed first, so such clients report an empty address and port 0, and still report their other flags (including `fake`), db and id. ### Testing New test in `tests/unit/moduleapi/misc.tcl`, "test module clientinfo api - called from a script", runs `test.clientinfo` through `EVAL` and checks the returned info. Without the fix the server crashes with signal 11. --------- Signed-off-by: Eran Liberty <eran.liberty@gmail.com> Co-authored-by: Bara' Hasheesh <bara.hasheesh@gmail.com> Backport-Source-PR: 5713 Signed-off-by: valkeyrie-ops[bot] <284117741+valkeyrie-ops[bot]@users.noreply.github.com>
AI backport resolution: source PR #4941Skip post-snapshot keys when expediting for MOVE and COPY in forkless BGSAVE 1 AI-edited file Claude Summary
AI-edited files requiring review
Full backport commit diff: commit 57c5477f3d47.
|
AI backport resolution: source PR #5584Fix double free of the key iterator on AOF rewrite write error 1 AI-edited file Claude Summary
AI-edited files requiring review
Full backport commit diff: commit d20e8c0f31c4.
|
killAppendOnlyChild() waits with waitpid(-1, ...), which reaps any child that has exited, not just the AOF rewrite child, and drops its status. If a forked SCRIPT DEBUG session has ended but serverCron hasn't reaped it yet, stopping AOF during a rewrite reaps it there. Its pid then stays in the debugger children list, so serverCron logs "waitpid() returned an error" on every tick, and on shutdown the stale pid, which may belong to an unrelated process by then, gets a SIGKILL. This patch waits for server.child_pid only, like TerminateModuleForkChild() already does. serverCron doesn't reap children while a script is running, so the new test ends the debug session while the server is in a busy script, and starts and kills the rewrite right after the script. Once the debug session child is reaped, it checks that the server doesn't try to kill it on shutdown. This affects all versions. Signed-off-by: Sarthak Aggarwal <sarthagg@amazon.com> Backport-Source-PR: 5529 Signed-off-by: valkeyrie-ops[bot] <284117741+valkeyrie-ops[bot]@users.noreply.github.com>
Forkless BGSAVE stores its temp and final RDB paths relative to the cwd and renames on a BIO thread after the iterator finishes. A `CONFIG SET dir` in between makes the rename resolve against the new dir, so it fails with ENOENT, the save reports `err`, and the cleanup unlink misses too, leaving `temp-forkless-*.rdb` in the old dir. A fork-based save is unaffected because the child keeps its cwd. This resolves both paths against the cwd when the save starts. Signed-off-by: Madelyn Olson <madelyneolson@gmail.com> Backport-Source-PR: 5106 Signed-off-by: valkeyrie-ops[bot] <284117741+valkeyrie-ops[bot]@users.noreply.github.com>
Signed-off-by: valkeyrie-ops[bot] <284117741+valkeyrie-ops[bot]@users.noreply.github.com>
…5113) During a forkless save, a command inside EXEC that writes a key EXEC did not expedite aborts the server on `serverAssert(!(mustBlock && c->flag.multi && !c->flag.script))` in `bgIteration_blockClientIfRequired()`. EXEC predicts the keys a transaction will write, but it cannot see a `SWAPDB` run by a queued script, and it does not remap the destination database of a `COPY ... DB n` or `MOVE` after a queued `SWAPDB`. This uses the synchronous wait that scripts already use for undeclared keys, so the command waits for the save thread to hand the entry back instead of crashing. Signed-off-by: Madelyn Olson <madelyneolson@gmail.com> Backport-Source-PR: 5113 Signed-off-by: valkeyrie-ops[bot] <284117741+valkeyrie-ops[bot]@users.noreply.github.com>
…#5144) A replica loading a disk-based full sync processes events from inside `rdbLoad()`. If a cluster bus message handled there moves it to a new primary (an ordinary failover, or `CLUSTER FAILOVER TAKEOVER` on another replica), the sync being loaded is cancelled and a new handshake starts. When the load returns, the replica finalizes the cancelled sync anyway. It closes the new sync's temp file, reports the link as up with the new primary's replication ID, and keeps the old primary's dataset with no further resync. This patch treats a load that spans a `cancelReplicationHandshake()` call as failed and leaves the newer sync's state alone. Signed-off-by: Madelyn Olson <madelyneolson@gmail.com> Backport-Source-PR: 5144 Signed-off-by: valkeyrie-ops[bot] <284117741+valkeyrie-ops[bot]@users.noreply.github.com>
AI backport resolution: source PR #5106Pin forkless save paths to the dir the save started in 1 AI-edited file Claude Summary
AI-edited files requiring review
Full backport commit diff: commit bdea78d5115e.
|
The Daily reply-schemas-validator job fails since the test "Active Defrag pubsub with a pending channel reply" was added in #4971: Reply schema validation failed for CONFIG SET min-io-threads-avoid-copy-reply: 'OK' was expected (response: null) The test runs "config set min-io-threads-avoid-copy-reply 1" on a server without IO threads. After that, isCopyAvoidPreferred() returns 1 for every reply, so each reply buffer starts with a binary payload header (and holds object pointers for bulk strings) instead of plain RESP. The req-res logger (reqresAppendResponse() in src/logreqres.c) copies the reply buffer as is, so the .reqres file holds the header before "+OK" and the validator cannot parse the reply. The test needs copy avoidance for its whole body, so it cannot run in log-req-res mode. Tag it with logreqres:skip, like the other tests that set min-io-threads-avoid-copy-reply to 1 (tests/unit/networking.tcl and tests/unit/obuf-limits.tcl). It still runs in all other jobs. The {0} result pattern is the value that "$listener close" returns. Fixes #5642 Signed-off-by: Eran Ifrah <eifrah@amazon.com> Backport-Source-PR: 5655 Signed-off-by: valkeyrie-ops[bot] <284117741+valkeyrie-ops[bot]@users.noreply.github.com>
Backport sweep for 9.2
Automated cherry-picks from PRs marked "To be backported".
Applied
AI resolution details are posted as comments on this PR when available.
Skipped
These candidates were evaluated but contribute no change to this branch, e.g. the fix targets code that does not exist here. No backport commit was created for them.
Needs attention
These candidates could not be applied automatically and need a maintainer to follow up.
1 candidate(s)
Generated by valkey-ci-agent using Claude Code.