Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Runtime diagnostics for leaked messages in unbounded channels (part 2) #13020

Merged
merged 4 commits into from
Dec 27, 2022

Conversation

dmitry-markin
Copy link
Contributor

This is a follow-up PR to #12971 addressing code review issues.

polkadot companion: paritytech/polkadot#6481

@dmitry-markin dmitry-markin added A0-please_review Pull request needs code review. B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit labels Dec 26, 2022
@@ -62,7 +62,7 @@ pub fn channel(name: &'static str, queue_size_warning: i64) -> (Sender, Receiver
queue_size: queue_size.clone(),
queue_size_warning,
warning_fired: false,
creation_backtrace: Backtrace::capture(),
creation_backtrace: Backtrace::new_unresolved(),
Copy link
Member

Choose a reason for hiding this comment

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

Can we not use the channel from utils here?

The metrics field is always None or?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sender is not accessible on its own, but only via OutChannels. metrics is inserted when a new Sender is added with OutChannels::push():

/// Adds a new [`Sender`] to the collection.
pub fn push(&mut self, sender: Sender) {
let mut metrics = sender.metrics.lock();
debug_assert!(metrics.is_none());
*metrics = Some(self.metrics.clone());

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've updated the comment to indicate that metrics will be initialized.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Metrics in out_events.rs and mpsc.rs seem different, so I don't know how to reuse utils version of the channel.

Copy link
Member

Choose a reason for hiding this comment

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

Okay ty. At some point we should probably merge both implementations. The metrics are probably not that different.

self.name, self.queue_size_warning,
),
}
let mut bt = self.creation_backtrace.lock().expect("another thread panicked.");
Copy link
Member

Choose a reason for hiding this comment

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

I'm not really sure about the mutex here. I mean I get why, but we could also just use Arc and then clone the backtrace here into some mutable value to resolve it.

let mut backtrace = (*self.creation_backtrace).clone();
backtrace.resolve();

But I don't know if not using a mutex is wort the clone 🤷

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. It's a rare one-time event anyway, not a big deal.

@@ -62,7 +62,7 @@ pub fn channel(name: &'static str, queue_size_warning: i64) -> (Sender, Receiver
queue_size: queue_size.clone(),
queue_size_warning,
warning_fired: false,
creation_backtrace: Backtrace::capture(),
creation_backtrace: Backtrace::new_unresolved(),
Copy link
Member

Choose a reason for hiding this comment

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

Okay ty. At some point we should probably merge both implementations. The metrics are probably not that different.

@bkchr
Copy link
Member

bkchr commented Dec 27, 2022

bot merge

@paritytech-processbot
Copy link

Waiting for commit status.

@paritytech-processbot paritytech-processbot bot merged commit 6fe8cd4 into master Dec 27, 2022
@paritytech-processbot paritytech-processbot bot deleted the dm-unbounded-warning-folow-up branch December 27, 2022 10:05
rossbulat pushed a commit that referenced this pull request Dec 28, 2022
#13020)

* Fix code review issues

* Clarify doc

* Get rid of backtrace mutex

* kick CI
ltfschoen pushed a commit to ltfschoen/substrate that referenced this pull request Feb 22, 2023
paritytech#13020)

* Fix code review issues

* Clarify doc

* Get rid of backtrace mutex

* kick CI
ark0f pushed a commit to gear-tech/substrate that referenced this pull request Feb 27, 2023
paritytech#13020)

* Fix code review issues

* Clarify doc

* Get rid of backtrace mutex

* kick CI
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-please_review Pull request needs code review. B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants