Skip to content

fix(rust): leaking connections, clippy and tests + examples#1

Open
thlorenz wants to merge 2 commits intomainfrom
main+conn-fix
Open

fix(rust): leaking connections, clippy and tests + examples#1
thlorenz wants to merge 2 commits intomainfrom
main+conn-fix

Conversation

@thlorenz
Copy link
Copy Markdown
Collaborator

@thlorenz thlorenz commented Mar 25, 2026

Summary

Fix connection leak caused by StreamHandle not signaling the background stream to shut down when dropped. Also fix broken imports and clippy warnings across all Rust examples and tests.

Details

rust/src/client.rs

  • StreamHandle no longer derives Clone. It now owns a watch::Sender<bool> that signals the background async stream to terminate when the handle is dropped.
  • Added a Drop impl that sends true on the close channel.
  • The stream loop listens on close_rx.changed() inside tokio::select! — both during active streaming and during the 5-second reconnect delay — so shutdown is immediate regardless of state.

Examples & Tests

  • 8 examples (account_sub, accounts_data_slice_sub, block_meta_sub, block_sub, entry_sub, slot_sub, transaction_sub, transaction_status_sub) had broken imports referencing a nonexistent yellowstone_grpc_proto crate; replaced with helius_laserstream::grpc re-exports.
  • stream_write_example.rs and subscription_replacement_persistence.rs: removed handle.clone() usage since StreamHandle is no longer Clone; moved handle directly into spawned tasks.
  • compression-advanced.rs: refactored field reassignment into struct literal initialization to satisfy clippy.
  • block_integrity.rs: removed redundant ..Default::default() on exhaustive struct.
  • transaction_integrity.rs: extracted StatusMap type alias to fix type_complexity warning.
  • ~30 uninlined_format_args clippy fixes across examples and tests.

Summary by CodeRabbit

  • New Features

    • Added graceful shutdown mechanism for stream handling.
  • Refactor

    • Reorganized internal imports across example files for better code organization.
    • Updated code formatting throughout examples and tests for consistency.
    • Simplified stream handle management by removing unnecessary cloning.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 25, 2026

Walkthrough

Multiple example files updated import paths from yellowstone_grpc_proto::geyser to helius_laserstream::grpc and refactored string formatting to use inline variable interpolation. The core client library added graceful shutdown support via a Drop implementation and tokio::select! logic. Test files underwent minor formatting standardization.

Changes

Cohort / File(s) Summary
Examples: gRPC Import and Output Formatting
rust/examples/account_sub.rs, rust/examples/accounts_data_slice_sub.rs, rust/examples/block_meta_sub.rs, rust/examples/block_sub.rs, rust/examples/entry_sub.rs, rust/examples/slot_sub.rs, rust/examples/transaction_status_sub.rs, rust/examples/transaction_sub.rs
Updated imports to pull SubscribeRequest and filter types from helius_laserstream::grpc instead of yellowstone_grpc_proto::geyser. Refactored debug and error output formatting from positional {:?} syntax to inline capture ({update:?} and {e:?}).
Examples: Output Formatting Only
rust/examples/basic_usage.rs, rust/examples/channel-options-example.rs, rust/examples/compression-example.rs, rust/examples/preprocessed_transaction_sub.rs, rust/examples/verify_no_internal_filters.rs
Refactored output formatting to use inline variable interpolation instead of positional arguments in println! and eprintln! macros.
Examples: Advanced Updates
rust/examples/compression-advanced.rs, rust/examples/stream_write_example.rs
compression-advanced.rs converted ChannelOptions initialization from mutable builder pattern to struct-literal form. stream_write_example.rs removed handle_clone and updated error formatting.
Core Library: StreamHandle Shutdown
rust/src/client.rs
Added close_tx: Option<watch::Sender<bool>> field to StreamHandle with a Drop implementation to signal graceful shutdown. Modified subscription loop and reconnection backoff to use tokio::select! for monitoring close signal. Updated error message formatting throughout.
Tests: Formatting and Cleanup
rust/test/account_integrity.rs, rust/test/block_integrity.rs, rust/test/subscription_replacement_persistence.rs, rust/test/transaction_integrity.rs
Removed unused imports, refactored println! and eprintln! to use inline variable interpolation, eliminated handle clones, and introduced type aliases for improved readability.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately reflects the main changes: fixing a connection leak in StreamHandle, resolving clippy warnings, and updating examples/tests. It directly maps to the substantive code changes described in the PR objectives.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch main+conn-fix

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.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

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 the current code and only fix it if needed.

Inline comments:
In `@rust/examples/stream_write_example.rs`:
- Around line 75-77: The spawned writer task currently takes ownership of
StreamHandle (variable handle) and drops it when the task exits, which sends a
close signal and can terminate streaming early; fix by keeping the original
handle in the main scope and instead clone an Arc (or the handle's cloneable
wrapper) into the writer task so the task uses a cloned handle while the main
retains ownership — locate usages of handle in the writer spawn (where
transaction_request is written) and change to clone the shared handle for the
task, ensuring the main scope's handle is not moved/dropped when the task
finishes (also apply the same change for the other writer block around the
second occurrence).

In `@rust/test/subscription_replacement_persistence.rs`:
- Around line 127-134: The writer task currently owns and drops the StreamHandle
(`handle`) after write(), which triggers its Drop and can prematurely close the
stream; instead keep the live handle in the main task and share it with the
spawned writer using a thread-safe reference (e.g., wrap the StreamHandle in an
Arc and clone that Arc into the writer task or use Arc<Mutex<...>> if mutation
is required) so the original Arc in main remains until post-write reconnect
validation completes; update references to `handle` in the spawned task to use
the cloned Arc and ensure the main retains ownership of the original Arc until
validation finishes.
🪄 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: c8c1a9ed-868d-48d5-8408-80695b6bc8c0

📥 Commits

Reviewing files that changed from the base of the PR and between 61381e4 and 8d0cdd7.

⛔ Files ignored due to path filters (1)
  • javascript/Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (20)
  • rust/examples/account_sub.rs
  • rust/examples/accounts_data_slice_sub.rs
  • rust/examples/basic_usage.rs
  • rust/examples/block_meta_sub.rs
  • rust/examples/block_sub.rs
  • rust/examples/channel-options-example.rs
  • rust/examples/compression-advanced.rs
  • rust/examples/compression-example.rs
  • rust/examples/entry_sub.rs
  • rust/examples/preprocessed_transaction_sub.rs
  • rust/examples/slot_sub.rs
  • rust/examples/stream_write_example.rs
  • rust/examples/transaction_status_sub.rs
  • rust/examples/transaction_sub.rs
  • rust/examples/verify_no_internal_filters.rs
  • rust/src/client.rs
  • rust/test/account_integrity.rs
  • rust/test/block_integrity.rs
  • rust/test/subscription_replacement_persistence.rs
  • rust/test/transaction_integrity.rs

Comment thread rust/examples/stream_write_example.rs
Comment thread rust/test/subscription_replacement_persistence.rs
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.

1 participant