-
Notifications
You must be signed in to change notification settings - Fork 177
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
Conversation
@@ -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)), |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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)),
}
}
}
There was a problem hiding this comment.
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 ☝️
There was a problem hiding this comment.
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
).
Closing #560
Heads up: request limit is shared by the client when it's cloned.