-
I'm struggling a bit to build a minimal reproduction, but I hope the question will be clear enough without that. I've got a stream that I give to gRPC call, and a resultant stream from gRPC. I want to record some data and log it once both streams are completed, so I made a naïve implementation that has a recorder in impl Drop for Recorder {
fn drop(&mut self) {
info!("{self:?}");
}
}
async fn connect(…) -> Result<BoxStream<'static, CallResult>, Status> {
let recorder = Arc::new(Mutex::new(Recorder::new()));
let request = Request::new(
ReceiverStream::new(rx)
.inspect(move |req| {
if let Ok(mut recorder) = recorder.lock() {
recorder.request(req)
};
}),
);
Ok(grpc_client
.rpc_call(request)
.await?
.into_inner()
.inspect(move |result| {
if let Ok(mut recorder) = recorder.lock() {
recorder.response(&result)
}
})
.boxed())
} I was not sure if an outer span will be correctly applied, the function two calls higher was instrumented with a span if that's important. It appears, the call to For now I've tried to pass a weak reference to the outgoing stream and keep the original So, I have two questions, really:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
So when you're dealing with Also note that the drop order matters. If you enter a spam and are holding a guard, if the guard is dropped before your The best way to make sure is to use I don't understand your second question. |
Beta Was this translation helpful? Give feedback.
Right, if you can carry the span around, that's the way to go to make sure it's in that span.
Right, once you upgrade a
Weak
into anArc
, thatArc
also contributes to the strong count. But if you then drop all the otherArc
s and then drop thisArc
, the object will be deallocated regardless of whether you still hold theWeak
or not. It doesn't really matter whether theArc
s come from cloning or upgrading, once the last one is dropped, then the object is deallocated and you won't be able to upgrade any moreWeak
s.