Skip to content

fix(request-sharing): correct clone, gc task lifetime, and drop zeroing for RequestSharing#4411

Open
metalurgical wants to merge 3 commits into
cowprotocol:mainfrom
metalurgical:request_sharig_clone_impl_fix
Open

fix(request-sharing): correct clone, gc task lifetime, and drop zeroing for RequestSharing#4411
metalurgical wants to merge 3 commits into
cowprotocol:mainfrom
metalurgical:request_sharig_clone_impl_fix

Conversation

@metalurgical
Copy link
Copy Markdown
Contributor

@metalurgical metalurgical commented May 14, 2026

Description

Correct Clone implementation for RequestSharing to share the in-flight cache instead of creating a new one, allow the GC task to exit when all handles are dropped, and fix Drop to only zero on the last handle.

Changes

  • Change in_flight: self.in_flight.clone() instead of Default::default()
  • spawn_gc modified to check Arc and exit once all handles are gone.
  • Drop checks Arc::strong_count(&self.in_flight) == 1
  • Added tests

How to test

cargo nextest run -p request-sharing

…g independent one

Additionally, gc task exits when all handles dropped, drop only zeroes on last handle
@metalurgical metalurgical requested a review from a team as a code owner May 14, 2026 12:18
Copy link
Copy Markdown

@claude claude Bot left a comment

Choose a reason for hiding this comment

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

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request updates the RequestSharing implementation to share the in-flight request cache across clones and modifies the garbage collection task to use a weak reference, ensuring the task terminates when all handles are dropped. A critical race condition was identified where the request_sharing_cached_items metric might remain at a non-zero value if the GC task holds a strong reference during the final drop of the cache handles. It is recommended to explicitly zero the metric within the GC task's exit path to ensure consistent state reporting.

Comment thread crates/request-sharing/src/lib.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