Skip to content

Conversation

@currantw
Copy link
Collaborator

@currantw currantw commented Nov 5, 2025

Problem

The TestScanAsync_InvalidCursorId test was failing due to a race condition in the Rust FFI layer. When an invalid cursor ID was provided to cluster scan operations, the Rust code was calling the failure callback twice:

  1. First callback: Immediate failure when detecting invalid cursor ID.
  2. Second callback: From the panic guard when the function exited, because panic_guard.panicked was not set.

This caused SetException to be called multiple times on the same Message object in C#, leading to assertion failures and process crashes. This caused the test runner to stall while it waited for the process to complete.

Solution

  1. Fixed double callback issue: Added panic_guard.panicked = false before early returns to prevent the panic guard from triggering additional failure callbacks
  2. Improved error handling: Used report_error function instead of manual string formatting to avoid potential dangling pointer issues
  3. Simplified test: Refactored the test to use inline lambda expressions for cleaner code

Changes

  • rust/src/lib.rs: Fixed panic guard handling and improved error reporting in request_cluster_scan
  • tests/Valkey.Glide.IntegrationTests/ScanTests.cs: Simplified test implementation

Fixes #132

@currantw currantw requested a review from a team as a code owner November 5, 2025 03:38
@currantw currantw requested a review from Copilot November 5, 2025 03:38
@currantw currantw self-assigned this Nov 5, 2025
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors error handling in the cluster scan functionality and simplifies the corresponding test. The changes improve code consistency and fix potential panic reporting issues.

  • Refactored Rust error handling to use the report_error helper function consistently
  • Added proper panic guard cleanup before early returns to prevent false panic reporting
  • Simplified C# test code by removing unnecessary intermediate variables

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
tests/Valkey.Glide.IntegrationTests/ScanTests.cs Simplified test by inlining client creation and removing unused exception variable
rust/src/lib.rs Fixed error reporting to use helper function and properly reset panic guard before early returns

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Collaborator

@yipin-chen yipin-chen left a comment

Choose a reason for hiding this comment

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

LGTM

@currantw currantw merged commit d484024 into valkey-io:main Nov 5, 2025
11 checks passed
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.

Test Failure - TestScanAsync_InvalidCursorId

3 participants