Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(http client): impl Clone #583

Merged
merged 1 commit into from
Nov 29, 2021
Merged

fix(http client): impl Clone #583

merged 1 commit into from
Nov 29, 2021

Conversation

niklasad1
Copy link
Member

@niklasad1 niklasad1 commented Nov 29, 2021

Closing #560

Heads up: request limit is shared by the client when it's cloned.

@niklasad1 niklasad1 requested a review from a team as a code owner November 29, 2021 16:47
@@ -75,7 +75,7 @@ impl HttpClientBuilder {
.map_err(|e| Error::Transport(e.into()))?;
Ok(HttpClient {
transport,
id_manager: RequestIdManager::new(self.max_concurrent_requests),
id_manager: Arc::new(RequestIdManager::new(self.max_concurrent_requests)),
Copy link
Contributor

Choose a reason for hiding this comment

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

dq: could this be a Box too?

Copy link
Contributor

@dvdplm dvdplm Nov 29, 2021

Choose a reason for hiding this comment

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

Maybe with:

impl Clone for RequestIdManager {
	fn clone(&self) -> Self {
		RequestIdManager {
			current_pending: self.current_pending.clone(),
			max_concurrent_requests: self.max_concurrent_requests.clone(),
			current_id: AtomicU64::new(self.current_id.load(std::sync::atomic::Ordering::SeqCst)),
		}
	}
}

Copy link
Member Author

@niklasad1 niklasad1 Nov 29, 2021

Choose a reason for hiding this comment

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

Because we rely on the strong count on current_pending for how many concurrent requests cloning current_pending it increase the strong count and it will not work properly.

Thus, that's why I used Arc<RequestIdManager>.

Box only works when RequestIdManager is clone right?! I don't want it to be Clone because the reason ☝️

Copy link
Contributor

Choose a reason for hiding this comment

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

Box only works when RequestIdManager is clone right?! I don't want it to be Clone because the reason ☝️

Ah, right, ok, I get it now.

Yes, RequestIdManager would have to be Clone (and if it were you wouldn't need nor Box or Arc).

@dvdplm dvdplm merged commit 15b2f23 into master Nov 29, 2021
@dvdplm dvdplm deleted the na-http-client-clone branch November 29, 2021 21:30
@slumber slumber mentioned this pull request Dec 9, 2021
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.

4 participants