test: fix false-positive corruption in reload-under-load harness#81
Conversation
Filter compresses with a referenced dictionary (zstd_dict_file / ZSTD_CCtx_refCDict) but the test's decode step never passed -D, so libzstd correctly rejected every response as corrupted. Not a real bug in the filter module — verified 3x clean after fix (593-625 reqs per run, 6 SIGHUP reloads, 4-way load).
📝 WalkthroughWalkthroughThe reload-under-load test now passes nginx’s Zstandard dictionary to its response decoder, ensuring compressed responses are decoded with the same dictionary across reload timing scenarios. ChangesReload verification
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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 `@tools/test_reload_under_load.py`:
- Around line 144-151: Update the subprocess.run invocation that decodes the
response blob to explicitly pass check=False, preserving the existing manual
handling of non-zero decoder exits and satisfying Ruff PLW1510.
🪄 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: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 073dd222-ee73-4331-9291-174eb05ad355
📒 Files selected for processing (1)
tools/test_reload_under_load.py
| # nginx.conf below sets zstd_dict_file, so every response is compressed | ||
| # against that dictionary (ZSTD_CCtx_refCDict in the filter module) -- | ||
| # the decoder needs the same dictionary via -D, or libzstd correctly | ||
| # rejects the frame as "Data corruption detected" even though nothing is | ||
| # actually corrupt. Omitting -D here previously made this test fail on | ||
| # every run regardless of reload timing (any response, any size). | ||
| r = subprocess.run([zstd_bin, "-dq", "-c", "-D", str(dict_path)], | ||
| input=blob, capture_output=True) |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -eu
ruff check --select PLW1510 tools/test_reload_under_load.pyRepository: myguard-labs/nginx-zstd-module
Length of output: 861
Add check=False to this subprocess.run call. The non-zero decoder exit is handled manually, and the explicit flag silences Ruff PLW1510.
🧰 Tools
🪛 ast-grep (0.44.1)
[error] 149-150: Command coming from incoming request
Context: subprocess.run([zstd_bin, "-dq", "-c", "-D", str(dict_path)],
input=blob, capture_output=True)
Note: [CWE-78] Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection').
(subprocess-from-request)
🪛 Ruff (0.15.21)
[error] 150-150: subprocess call: check for execution of untrusted input
(S603)
[warning] 150-150: subprocess.run without explicit check argument
Add explicit check=False
(PLW1510)
🤖 Prompt for 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.
In `@tools/test_reload_under_load.py` around lines 144 - 151, Update the
subprocess.run invocation that decodes the response blob to explicitly pass
check=False, preserving the existing manual handling of non-zero decoder exits
and satisfying Ruff PLW1510.
Source: Linters/SAST tools
Summary
Issue #80 reported "data corruption" under SIGHUP reload with large (CSTREAM_IN+1-sized) bodies. Root cause turned out to be the test harness, not the filter module: nginx.conf sets
zstd_dict_file, so the filter compresses every response against that dictionary viaZSTD_CCtx_refCDict. The test's decode step never passed-D <dict>tozstd -d, so libzstd correctly rejected the dictionary-compressed frame as corrupted.one()intools/test_reload_under_load.pyto decode with-D dict_path.filter/ngx_http_zstd_filter_module.c— the byte-accounting bug I originally suspected does not exist.Closes #80.
Test plan
python3 tools/test_reload_under_load.py --nginx-binary <debug build> --reloads 6 --workers 4 --duration 18— 3 consecutive clean runsSummary by CodeRabbit