Skip to content

Fix memory leaks in unit tests - #523

Merged
wprzytula merged 2 commits into
scylladb:masterfrom
wprzytula:tmp/leakfix
Oct 26, 2026
Merged

wprzytula merged 2 commits into
scylladb:masterfrom
wprzytula:tmp/leakfix

Conversation

@wprzytula

@wprzytula wprzytula commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

The unit tests leaked 11 allocations. None of them is a leak in the driver: every one is a test that creates an object through the C API and never frees it. They are invisible to cargo test, and they show up as soon as the suite runs under valgrind.

  • test_typecheck_on_append_to_collection builds a data type with ArcFFI::into_ptr() in seven blocks, and frees it in three of them.
  • regression_empty_collection_data_type_test never frees its collection.
  • regression_empty_tuple_data_type_test never frees its tuple.
  • session_resolves_exec_profile_on_first_query passes the result of cass_session_execute() straight into cass_future_error_code(), so the future is never freed. It does this four times.

With these fixed, valgrind reports one remaining leak: the Tokio runtime, which the driver never drops on purpose.

This makes it possible to run the unit tests under valgrind in the CI, as the C++ integration tests already are.

Bonus

Tokio is updated to 1.54.1, following a cargo deny's advisory.

Pre-review checklist

  • I have split my patch into logically separate commits.
  • All commit messages clearly explain what they change and why.
  • PR description sums up the changes and reasons why they should be introduced.
  • [ ] I have provided docstrings for the public items that I want to introduce.
  • [ ] I have adjusted the documentation in ./docs/source/.
  • [ ] I have implemented Rust unit tests for the features/changes introduced.
  • [ ] I have enabled appropriate tests in Makefile in {SCYLLA,CASSANDRA}_(NO_VALGRIND_)TEST_FILTER.
  • [ ] I added appropriate Fixes: annotations to PR description.

@coderabbitai

coderabbitai Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: QUIET
  • Plan: Essentials
  • Run ID: 398f5201-fd89-4608-8a9b-411ac93db0d8
Commits

Reviewing files that changed from the base of the PR and between 74a8720 and 1bc50ec.

Files selected for processing: 3
  • scylla-rust-wrapper/src/cql_types/collection.rs
  • scylla-rust-wrapper/src/cql_types/tuple.rs
  • scylla-rust-wrapper/src/session.rs

Included review availability: This review used your included allowance. 4 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 5 reviews per hour.

Walkthrough

Tests now explicitly free collection data-type pointers, an empty collection and tuple, and statement and batch execution futures. The execution-profile tests retain their existing expected error codes.

Priority: Normal

Change: Other

Merge Risk: Minimal · up to 1bc50

No actionable merge-blocking risk was identified.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: fixing memory leaks in unit tests.
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.
Description check Passed The description states the problem (11 leaked allocations in unit tests), names each affected test, explains the impact on valgrind runs, and gives the reason for the change. It also notes the remaini…
Full details: Description check

Explanation

The description states the problem (11 leaked allocations in unit tests), names each affected test, explains the impact on valgrind runs, and gives the reason for the change. It also notes the remaining Tokio runtime leak and a Tokio bump to 1.54.1. The checklist has its first three items marked, and the remaining items are struck through, which is acceptable for a test-only fix.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@qodo-scylladb

qodo-scylladb Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Great, no issues found!

Qodo reviewed your code and found no material issues that require review
Tip of the day
💡 Did you know, you can type 'qodo, fix this' on a finding and the fix lands right on your PR

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗


Powered by Qodo

@wprzytula
wprzytula requested a review from Lorak-mmk October 24, 2026 21:00
@codecov

codecov Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 72.38%. Comparing base (74a8720) to head (7eff2f1).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #523   +/-   ##
=======================================
  Coverage   72.38%   72.38%           
=======================================
  Files          31       31           
  Lines        8198     8198           
=======================================
  Hits         5934     5934           
  Misses       2264     2264           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

RUSTSEC-2026-0386 reports that `tokio::io::unix::AsyncFd` has safe
constructors that accept any `T: AsRawFd`. Safe code can therefore build an
`AsyncFd` from an arbitrary or closed file descriptor, and a closed and
reused descriptor can lead to a use-after-free in the I/O driver.

The advisory asks for Tokio 1.51.6, 1.53.3 or 1.54.0 and later, where those
constructors are deprecated in favour of unsafe ones. This bumps the lockfile
to 1.54.1.

The driver does not call `AsyncFd` itself. Tokio is a dependency of
rust-driver, so the fix is a lockfile update and nothing more.

`cargo deny check` reports advisories, bans, licenses and sources all ok.
The unit tests leaked 11 allocations. None of them is a leak in the driver:
every one is a test that creates an object through the C API and never frees
it. They are invisible to `cargo test`, and they show up as soon as the
suite runs under valgrind.

- `test_typecheck_on_append_to_collection` builds a data type with
  `ArcFFI::into_ptr()` in seven blocks, and frees it in three of them.
- `regression_empty_collection_data_type_test` never frees its collection.
- `regression_empty_tuple_data_type_test` never frees its tuple.
- `session_resolves_exec_profile_on_first_query` passes the result of
  `cass_session_execute()` straight into `cass_future_error_code()`, so the
  future is never freed. It does this four times.

With these fixed, valgrind reports one remaining leak: the Tokio runtime,
which the driver never drops on purpose.

This makes it possible to run the unit tests under valgrind in the CI, as
the C++ integration tests already are.
@wprzytula wprzytula self-assigned this Oct 26, 2026
@wprzytula wprzytula added this to the 1.2 milestone Oct 26, 2026
@wprzytula
wprzytula merged commit abfb5e2 into scylladb:master Oct 26, 2026
14 checks passed
@wprzytula
wprzytula deleted the tmp/leakfix branch October 26, 2026 12:35
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.

2 participants