Skip to content

Update deps/libvalkey to version 0.5.0#3697

Merged
zuiderkwast merged 1 commit into
valkey-io:unstablefrom
bjosv:libvalkey-0.5.0
May 13, 2026
Merged

Update deps/libvalkey to version 0.5.0#3697
zuiderkwast merged 1 commit into
valkey-io:unstablefrom
bjosv:libvalkey-0.5.0

Conversation

@bjosv

@bjosv bjosv commented May 13, 2026

Copy link
Copy Markdown
Contributor

Lift libvalkey to version 0.5.0 that includes pipelining optimizations and corrections needed for RDMA.

Update deps/libvalkey to version 0.5.0

Squashed 'deps/libvalkey/' changes from 45c2ed15c..cb5ff91aa

cb5ff91aa Release 0.5.0
cd3d5d8ff Fix potential heap-buffer-overflow in cluster error reply parsing (#305)
32c7c5d09 Refactor error handling to use valkeySetErrorFromErrno and valkeyClearError (#303)
e4b548b32 Remove support for external dict while still supporting external sds (#302)
61b27c453 Try all addresses from DNS before failing to connect (#300)
8aff94fab RDMA: Fix lost EPOLLIN/POLLIN events
b9285b5fc Optimize read buffer compaction and reduce copying (#294)
0fa809877 Additional overflow protection for MAP/ATTR
b26c56e87 Fix gcc warnings (#287)
...

git-subtree-dir: deps/libvalkey
git-subtree-split: cb5ff91aa5816807f0a549bd2b36e611253dfeb6

Squashed 'deps/libvalkey/' changes from 45c2ed15c..cb5ff91aa

cb5ff91aa Release 0.5.0
bbc332edd Bump the github-actions group across 1 directory with 4 updates
cd3d5d8ff Fix potential heap-buffer-overflow in cluster error reply parsing (valkey-io#305)
3dfeeb424 Bump the github-actions group with 3 updates
32c7c5d09 Refactor error handling to use valkeySetErrorFromErrno and valkeyClearError (valkey-io#303)
e4b548b32 Remove support for external dict while still supporting external sds (valkey-io#302)
a48bc663f Bump the github-actions group across 1 directory with 5 updates
61b27c453 Try all addresses from DNS before failing to connect (valkey-io#300)
8aff94fab RDMA: Fix lost EPOLLIN/POLLIN events
b9285b5fc Optimize read buffer compaction and reduce copying (valkey-io#294)
deaa88927 Bump the github-actions group across 1 directory with 5 updates
0fa809877 Additional overflow protection for MAP/ATTR
cb0aa80a4 Update CI (valkey-io#289)
b26c56e87 Fix gcc warnings (valkey-io#287)

git-subtree-dir: deps/libvalkey
git-subtree-split: cb5ff91aa5816807f0a549bd2b36e611253dfeb6

Signed-off-by: Björn Svensson <bjorn.a.svensson@est.tech>
@coderabbitai

coderabbitai Bot commented May 13, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

This pull request introduces reader buffer management APIs for zero-copy reading, refactors error handling across the library to use errno-derived messages instead of strerror, improves protocol parsing safety with overflow protection, migrates RDMA event handling from poll-based to epoll+eventfd-driven, widens SDS parameter types, and adds comprehensive test coverage including a new connection fallback test and dynamic OOM discovery.

Changes

Reader Buffer APIs, Error Handling, and Network Integration

Layer / File(s) Summary
Error handling API definitions and declarations
src/valkey.c, src/valkey_private.h
New valkeySetErrorFromErrno() constructs error messages from errno with optional prefix, and valkeyClearError() resets error state. These replace scattered strerror(errno) patterns across the library.
Reader buffer access APIs
include/valkey/read.h, src/read.c
valkeyReaderGetReadBuf() exposes the internal buffer for direct writes with capacity guarantees and minimum-byte constraints. valkeyReaderCommitRead() finalizes reads by updating SDS length and reader position state.
Reader protocol parsing and buffer integration
src/read.c, src/valkey.c
processAggregateItem() adds overflow guards when doubling MAP/ATTR element counts. valkeyReaderFeed() refactored to use the new buffer APIs instead of direct SDS concatenation. valkeyBufferRead() integrated to read directly into the reader's buffer via valkeyReaderGetReadBuf() and valkeyReaderCommitRead().
Network and socket error handling
src/net.c
valkeyNetRead(), valkeyNetWrite(), valkeyKeepAlive(), and valkeyContextConnectTcp() update I/O error reporting to use valkeySetErrorFromErrno(). TCP connect timeout enforcement improved via non-blocking connect with explicit EINPROGRESS handling.
TLS, cluster, and async error handling
src/tls.c, src/cluster.c, src/async.c
TLS connection/read failures now use OpenSSL error reason strings or valkeySetErrorFromErrno(). Cluster error classification adds reply->len guards before memcmp() to prevent out-of-bounds reads on truncated error strings. Async subscription callbacks use consistently named variables.
RDMA event loop refactoring with epoll and eventfd
src/rdma.c
Migration from poll() to epoll + eventfd for event-driven operation. New valkeyRdmaWaitEvent() multiplexes events from RDMA CM channel, completion channel, and eventfd. read_zc and write rewritten to use the new event mechanism. Epoll instance and eventfd created during connection setup and cleaned up on close.
SDS parameter type widening and library version bump
src/sds.c, src/sds.h, include/valkey/valkey.h
sdsIncrLen() parameter changed from int to ssize_t to avoid narrowing for larger increments. LIBVALKEY_VERSION_MINOR bumped from 4 to 5.
Error handling integration in reconnection and read loop
src/valkey.c
valkeyReconnect() uses valkeyClearError() helper. valkeyBufferRead() integrates new reader buffer APIs and copies reader error state to context on buffer-acquisition failures.
Test coverage for connection fallback, protocol limits, and OOM handling
tests/ut_connect_fallback.c, tests/client_test.c, tests/ct_out_of_memory_handling.c, tests/clusterclient.c, tests/clusterclient_async.c, tests/scripts/*
New ut_connect_fallback.c validates TCP address fallback via mocked getaddrinfo, freeaddrinfo, and connect. Protocol limits test verifies RESP3 MAP/ATTR overflow rejection. OOM tests refactored to dynamically discover allocation counts. Test output assertions updated to include Error: prefix in error messages.
GitHub Actions, build configuration, and documentation
.github/workflows/build.yml, .github/workflows/ci.yml, .github/workflows/release-drafter.yml, .github/workflows/spellcheck.yml, tests/CMakeLists.txt, docs/standalone.md, Makefile
GitHub Actions workflow versions bumped for FreeBSD, Solaris, CMake, vcpkg, and MSYS2 actions. CMake tests configuration adds ut_connect_fallback test with platform gating and Clang 22+ warning suppression. Documentation clarifies DNS multi-address connection behavior and per-address timeout application. Makefile comment narrowed to reference only SDS replacement.

🎯 4 (Complex) | ⏱️ ~45 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 30.19% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Update deps/libvalkey to version 0.5.0' clearly and concisely summarizes the main change—upgrading the vendored libvalkey library to version 0.5.0.
Description check ✅ Passed The description is well-detailed and directly related to the changeset, explaining the libvalkey version upgrade, key improvements (pipelining optimizations, RDMA corrections), and including the git commit history.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@deps/libvalkey/src/read.c`:
- Around line 823-827: The function valkeyReaderCommitRead currently trusts the
caller and only uses assert; replace that unsafe reliance with a runtime
capacity check: call sdsAvail(r->buf) to get writable capacity, compare it to
nread, and if nread > avail either clamp nread to avail or return an error (do
not call sdsIncrLen with an out-of-range value). Then call sdsIncrLen(r->buf,
(ssize_t)nread) and update r->len = sdslen(r->buf). Ensure the check uses the
same symbols (valkeyReaderCommitRead, r->buf, sdsAvail, sdsIncrLen, sdslen) so
no buffer overrun can occur in release builds.

In `@deps/libvalkey/src/valkey.c`:
- Around line 706-715: The function valkeySetErrorFromErrno risks overflowing
buf when prefix is too long: after calling snprintf you must check the return
value/len and ensure it does not exceed sizeof(buf)-1 before calling strerror_r;
if snprintf indicates truncation (len >= sizeof(buf)) set len = sizeof(buf)-1
and ensure buf[len] = '\0' and skip calling strerror_r (or call it with a
remaining size of 0 handled safely), otherwise compute remaining = sizeof(buf) -
len and call strerror_r(buf + len, remaining) so strerror_r cannot write out of
bounds, then call valkeySetError as before; update valkeySetErrorFromErrno to
enforce these bounds checks around snprintf/len and the subsequent strerror_r
invocation.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 4ec70f10-bd73-47c4-b1d9-299c4d72918b

📥 Commits

Reviewing files that changed from the base of the PR and between 5b167f4 and 6090185.

📒 Files selected for processing (26)
  • deps/libvalkey/.github/workflows/build.yml
  • deps/libvalkey/.github/workflows/ci.yml
  • deps/libvalkey/.github/workflows/release-drafter.yml
  • deps/libvalkey/.github/workflows/spellcheck.yml
  • deps/libvalkey/Makefile
  • deps/libvalkey/docs/standalone.md
  • deps/libvalkey/include/valkey/read.h
  • deps/libvalkey/include/valkey/valkey.h
  • deps/libvalkey/src/async.c
  • deps/libvalkey/src/cluster.c
  • deps/libvalkey/src/net.c
  • deps/libvalkey/src/rdma.c
  • deps/libvalkey/src/read.c
  • deps/libvalkey/src/sds.c
  • deps/libvalkey/src/sds.h
  • deps/libvalkey/src/tls.c
  • deps/libvalkey/src/valkey.c
  • deps/libvalkey/src/valkey_private.h
  • deps/libvalkey/tests/CMakeLists.txt
  • deps/libvalkey/tests/client_test.c
  • deps/libvalkey/tests/clusterclient.c
  • deps/libvalkey/tests/clusterclient_async.c
  • deps/libvalkey/tests/ct_out_of_memory_handling.c
  • deps/libvalkey/tests/scripts/client-disconnect-test.sh
  • deps/libvalkey/tests/scripts/moved-redirect-test.sh
  • deps/libvalkey/tests/ut_connect_fallback.c

Comment thread deps/libvalkey/src/read.c
Comment thread deps/libvalkey/src/valkey.c
@codecov

codecov Bot commented May 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 76.69%. Comparing base (5b167f4) to head (6090185).

Additional details and impacted files
@@             Coverage Diff              @@
##           unstable    #3697      +/-   ##
============================================
- Coverage     76.71%   76.69%   -0.03%     
============================================
  Files           162      162              
  Lines         80662    80662              
============================================
- Hits          61881    61861      -20     
- Misses        18781    18801      +20     

see 29 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@zuiderkwast zuiderkwast merged commit fdf13ca into valkey-io:unstable May 13, 2026
63 checks passed
@github-project-automation github-project-automation Bot moved this to To be backported in Valkey 9.1 May 13, 2026
lucasyonge pushed a commit that referenced this pull request May 14, 2026
Squashed 'deps/libvalkey/' changes from 45c2ed15c..cb5ff91aa

cb5ff91aa Release 0.5.0
cd3d5d8ff Fix potential heap-buffer-overflow in cluster error reply parsing (#305)
32c7c5d09 Refactor error handling to use valkeySetErrorFromErrno and valkeyClearError (#303)
e4b548b32 Remove support for external dict while still supporting external sds (#302)
61b27c453 Try all addresses from DNS before failing to connect (#300)
8aff94fab RDMA: Fix lost EPOLLIN/POLLIN events
b9285b5fc Optimize read buffer compaction and reduce copying (#294)
0fa809877 Additional overflow protection for MAP/ATTR
b26c56e87 Fix gcc warnings (#287)

git-subtree-dir: deps/libvalkey
git-subtree-split: cb5ff91aa5816807f0a549bd2b36e611253dfeb6

Signed-off-by: Björn Svensson <bjorn.a.svensson@est.tech>
@sarthakaggarwal97 sarthakaggarwal97 moved this from To be backported to Done in Valkey 9.1 May 16, 2026
madolson added a commit to madolson/valkey that referenced this pull request May 18, 2026
The libvalkey 0.5.0 update (valkey-io#3697) added DICT_INCLUDE_DIR=../../src/ to
the build flags, intending to reuse valkey's dict. However, this causes
libvalkey's dict.c to be excluded from the archive while the -I flag
order makes async.c and cluster.c compile against valkey's dict.h
(larger dictType with 9 fields). This works when DICT_INCLUDE_DIR is
passed because the Makefile also adds -I$(DICT_INCLUDE_DIR) before
-Isrc, so the headers match the linked code.

The actual bug is that passing DICT_INCLUDE_DIR excludes libvalkey's
dict.c from the archive, but valkey's dict.o (linked first) provides
dictCreate. Since async.c already picks up valkey's dict.h via
-I../../src/ (from SDS_INCLUDE_DIR), the struct layouts match and
everything works. The problem is that DICT_INCLUDE_DIR also triggers
the Makefile to filter out dict.c, creating a redundant dependency on
link order that breaks if anything changes.

Simply removing DICT_INCLUDE_DIR is safe because:
1. async.c already gets valkey's dict.h via -I../../src/ (SDS_INCLUDE_DIR)
2. libvalkey's dict.c is included in the archive but never pulled by
   the linker (valkey's dict.o satisfies the symbol first)
3. This matches what unstable does

Fixes sentinel crash on startup (signal 11, accessing address 0x90)
in sentinelReconnectInstance -> valkeyAsyncConnectBind path.

Signed-off-by: Madelyn Olson <madelyneolson@gmail.com>
madolson added a commit to madolson/valkey that referenced this pull request May 18, 2026
The libvalkey 0.5.0 update (valkey-io#3697) added DICT_INCLUDE_DIR=../../src/ to
the build flags. This excludes libvalkey's dict.c from the archive,
making the build depend on valkey's dictCreate being linked first.

However, the -I flag ordering (-I../../src/ from SDS_INCLUDE_DIR comes
before -Isrc) already causes libvalkey's source files to compile against
valkey's dict.h. So DICT_INCLUDE_DIR is redundant. Removing it lets
libvalkey's dict.c remain in the archive (harmlessly, since the linker
never pulls it), while the compilation still uses valkey's dict.h.

Without this fix, sentinel crashes immediately on startup:
  crashed by signal: 11, si_code: 1
  Accessing address: 0x90
in sentinelReconnectInstance -> valkeyAsyncConnectBind -> dictCreate.

This matches what unstable does (no DICT_INCLUDE_DIR).

Signed-off-by: Madelyn Olson <madelyneolson@gmail.com>
madolson added a commit that referenced this pull request May 18, 2026
Reverts the libvalkey portion of #3697 (0.5.0 update).

The 0.5.0 update introduced a `DICT_INCLUDE_DIR` feature whose
implementation is broken: `#include "dict.h"` in `async.c` and
`cluster.c` resolves to libvalkey's local `dict.h` (5-field `dictType`)
instead of valkey's (9-field `dictType`), causing a struct layout
mismatch with the linked `dictCreate`. This crashes every sentinel
instance on startup.

On unstable this works by coincidence because `dict` is typedef'd to
`hashtable` and the memory layout happens to have zeros at the critical
offset. On 9.1 with the traditional dict implementation, it reads
garbage and crashes.

The fix should be done upstream in libvalkey (the `DICT_INCLUDE_DIR`
feature needs to use `<dict.h>` instead of `"dict.h"`). Once that's
fixed upstream, we can re-update.

**Crash signature:**
```
signal 11, accessing address 0x90
sentinelReconnectInstance -> valkeyAsyncConnectBind -> dictCreate
```

Signed-off-by: Madelyn Olson <madelyneolson@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants