Skip to content

Exit with error when getRDB ftruncate fails#3945

Merged
madolson merged 1 commit into
valkey-io:unstablefrom
gluxier:fix-getrdb-ftruncate-error
Jun 11, 2026
Merged

Exit with error when getRDB ftruncate fails#3945
madolson merged 1 commit into
valkey-io:unstablefrom
gluxier:fix-getrdb-ftruncate-error

Conversation

@gluxier

@gluxier gluxier commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

When valkey-cli --rdb trims the EOF marker, a failed ftruncate only printed a warning but still reported success and exited 0, leaving a corrupt RDB file. This makes it exit non-zero on that failure, matching how the write() failure is already handled in the same function.

(Thank you, Madelyn, for tag teaming this with me.)

Previously a failed ftruncate printed a warning but still reported
'Transfer finished with success' and exited 0, leaving a corrupt RDB
file that looked successful. Exit non-zero to match the write() failure
handling in the same function.

Signed-off-by: Grace <glucier22@gmail.com>
@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 736a5746-a3f2-4e5f-ae2d-f202c69ddaa7

📥 Commits

Reviewing files that changed from the base of the PR and between 69004ca and 7bcb753.

📒 Files selected for processing (1)
  • src/valkey-cli.c

📝 Walkthrough

Walkthrough

The RDB file write path in getRDB() now treats file truncation failures as fatal. When ftruncate() fails while writing to a file destination, the function prints an error message and exits with status 1 instead of continuing execution.

Changes

RDB File Truncation Error Handling

Layer / File(s) Summary
RDB file truncation failure handling
src/valkey-cli.c
The getRDB() function now exits immediately on ftruncate(fd, payload) failure instead of logging and continuing, converting a recoverable error into a fatal condition.

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Exit with error when getRDB ftruncate fails' accurately describes the main change: making the function exit with an error status when ftruncate fails, which directly matches the changeset.
Description check ✅ Passed The description clearly explains the bug being fixed: ftruncate failures were not properly reported, leaving corrupt RDB files. It directly relates to the code changes and provides necessary context about the problem and solution.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 Infer (1.2.0)
src/valkey-cli.c

src/valkey-cli.c:53:10: fatal error: 'valkey/valkey.h' file not found
53 | #include <valkey/valkey.h>
| ^~~~~~~~~~~~~~~~~
1 error generated.
Error: the following clang command did not run successfully:
/opt/infer-linux-x86_64-v1.2.0/lib/infer/facebook-clang-plugins/clang/install/bin/clang-18
@/tmp/coderabbit-infer/7bcb753b57272bbb1af391420f2a7f31cd61b08e-6a265e23d06a081e/tmp/clang_command_.tmp.dfa087.txt
++Contents of '/tmp/coderabbit-infer/7bcb753b57272bbb1af391420f2a7f31cd61b08e-6a265e23d06a081e/tmp/clang_command_.tmp.dfa087.txt':
"-cc1" "-load"
"/opt/infer-linux-x86_64-v1.2.0/lib/infer/infer/bin/../../facebook-clang-plugins/libtooling/build/FacebookClangPlugin.dylib"
"-add-plugin" "BiniouASTExporter" "-plugin-arg-BiniouASTExporter" "-"
"-plugin-arg-BiniouASTExporter" "PREPEND_CURRENT_DIR=1"
"-plugin-arg-BiniouASTExporter" "MAX_STRING_SIZE=65535" "-cc1" "-triple"
"x86_64-unknown-linux-gnu" "-emit-obj" "-mrelax-all" "-disable-free"

... [truncated 695 characters] ...

"/opt/infer-linux-x86_64-v1.2.0/lib/infer/facebook-clang-plugins/clang/install/lib/clang/18/include"
"-internal-isystem" "/usr/local/include" "-internal-isystem"
"/usr/lib/gcc/x86_64-linux-gnu/12/../../../../x86_64-linux-gnu/include"
"-internal-externc-isystem" "/usr/include/x86_64-linux-gnu"
"-internal-externc-isystem" "/include" "-internal-externc-isystem"
"/usr/include" "-Wno-ignored-optimization-argument" "-Wno-everything"
"-ferror-limit" "19" "-fgnuc-version=4.2.1" "-fskip-odr-check-in-gmf"
"-D__GCC_HAVE_DWARF2_CFI_ASM=1" "-o"
"/tmp/coderabbit-infer/6a265e23d06a081e/file.o" "-x" "c"
"src/valkey-cli.c" "-O0" "-fno-builtin" "-include"
"/opt/infer-linux-x86_64-v1.2.0/lib/infer/infer/bin/../lib/clang_wrappers/global_defines.h"
"-Wno-everything"

Warning

Review ran into problems

🔥 Problems

Stopped waiting for pipeline failures after 30000ms. One of your pipelines takes longer than our 30000ms fetch window to run, so review may not consider pipeline-failure results for inline comments if any failures occurred after the fetch window. Increase the timeout if you want to wait longer or run a @coderabbit review after the pipeline has finished.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown

Caution

Failed to replace (edit) comment. This is likely due to insufficient permissions or the comment being deleted.

Error details
{"name":"HttpError","status":500,"request":{"method":"PATCH","url":"https://api.github.com/repos/valkey-io/valkey/issues/comments/4660698864","headers":{"accept":"application/vnd.github.v3+json","user-agent":"octokit.js/0.0.0-development octokit-core.js/7.0.6 Node.js/24","authorization":"token [REDACTED]","content-type":"application/json; charset=utf-8"},"body":{"body":"<!-- This is an auto-generated comment: summarize by coderabbit.ai -->\n<!-- review_stack_entry_start -->\n\n[![Review Change Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/valkey-io/valkey/pull/3945?utm_source=github_walkthrough&utm_medium=github&utm_campaign=change_stack)\n\n<!-- review_stack_entry_end -->\n<!-- This is an auto-generated comment: review in progress by coderabbit.ai -->\n\n> [!NOTE]\n> Currently processing new changes in this PR. This may take a few minutes, please wait...\n> \n> <details>\n> <summary>⚙️ Run configuration</summary>\n> \n> **Configuration used**: Repository UI\n> \n> **Review profile**: CHILL\n> \n> **Plan**: Pro Plus\n> \n> **Run ID**: `736a5746-a3f2-4e5f-ae2d-f202c69ddaa7`\n> \n> </details>\n> \n> <details>\n> <summary>📥 Commits</summary>\n> \n> Reviewing files that changed from the base of the PR and between 69004cae7f0c8417f63d96970128a332f1a0d5a1 and 7bcb753b57272bbb1af391420f2a7f31cd61b08e.\n> \n> </details>\n> \n> <details>\n> <summary>📒 Files selected for processing (1)</summary>\n> \n> * `src/valkey-cli.c`\n> \n> </details>\n> \n> \n\n<!-- end of auto-generated comment: review in progress by coderabbit.ai -->\n\n<!-- tips_start -->\n\n---\n\nThanks for using [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=valkey-io/valkey&utm_content=3945)! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.\n\n<details>\n<summary>❤️ Share</summary>\n\n- [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai)\n- [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai)\n- [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai)\n- [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)\n\n</details>\n\n\n<sub>Comment `@coderabbitai help` to get the list of available commands and usage tips.</sub>\n\n<!-- tips_end -->\n<!-- usage_tips_start -->\n\n> [!TIP]\n> <details>\n> <summary>You can validate your CodeRabbit configuration file in your editor.</summary>\n> \n> If your editor has YAML language server, you can enable auto-completion and validation by adding `# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json` at the top of your CodeRabbit configuration file.\n> \n> </details>\n\n<!-- usage_tips_end -->"},"request":{"retryCount":3,"signal":{},"retries":3,"retryAfter":16}}}

Comment thread src/valkey-cli.c
@codecov

codecov Bot commented Jun 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 76.67%. Comparing base (f7b236d) to head (7bcb753).
⚠️ Report is 3 commits behind head on unstable.

Files with missing lines Patch % Lines
src/valkey-cli.c 50.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##           unstable    #3945      +/-   ##
============================================
- Coverage     76.68%   76.67%   -0.01%     
============================================
  Files           162      162              
  Lines         80731    80734       +3     
============================================
- Hits          61910    61905       -5     
- Misses        18821    18829       +8     
Files with missing lines Coverage Δ
src/valkey-cli.c 60.17% <50.00%> (-0.01%) ⬇️

... and 20 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.

@madolson madolson merged commit 69d3f50 into valkey-io:unstable Jun 11, 2026
64 checks passed
sarthakaggarwal97 added a commit to sarthakaggarwal97/valkey that referenced this pull request Jun 22, 2026
When `valkey-cli --rdb` trims the EOF marker, a failed `ftruncate` only
printed a warning but still reported success and exited 0, leaving a
corrupt RDB file. This makes it exit non-zero on that failure, matching
how the `write()` failure is already handled in the same function.

(Thank you, Madelyn, for tag teaming this with me.)


(cherry picked from commit 69d3f50)

Signed-off-by: Grace <glucier22@gmail.com>
Co-authored-by: gluxier <glucier@linuxfoundation.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants