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

fail: check condition only when its failpoint is open #48

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

gengliqi
Copy link
Member

@gengliqi gengliqi commented Feb 5, 2020

Signed-off-by: Liqi Geng [email protected]

The check-condition code in failpoint runs all the time even it is not open.
It may lead to bad performance if checking the condition is very expensive
or misuse if someone modifies some variables in check-condition code and it's valid only when its failpoint is open. (my guess scenario)

src/lib.rs Show resolved Hide resolved
pub fn eval<R, F: FnOnce(Option<String>) -> R>(name: &str, f: F) -> Option<R> {
pub fn eval<R, F: FnOnce(Option<String>) -> R>(
name: &str,
f: F,
Copy link
Member

Choose a reason for hiding this comment

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

Can use impl trait here too.

return res;
}
}};
($name:expr, $cond:expr, $e:expr) => {{
if $cond {
fail_point!($name, $e);
if let Some(res) = $crate::eval($name, $e, || $cond) {
Copy link
Member

Choose a reason for hiding this comment

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

This makes it hard to share mutable states between $cond and $e.

Copy link
Collaborator

Choose a reason for hiding this comment

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

If true then we better add a test case that captures the expected behavior.

@gengliqi can you try adding a test case that shares mutable references between the two expressions and seeing if they worked previously but don't work after this patch?

@brson
Copy link
Collaborator

brson commented Feb 16, 2020

Here's a patch to fix CI: #49

Copy link
Collaborator

@brson brson left a comment

Choose a reason for hiding this comment

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

Per @BusyJay there is question about whether this patch regresses an existing capability. I've asked for a test case to capture that scenario.

return res;
}
}};
($name:expr, $cond:expr, $e:expr) => {{
if $cond {
fail_point!($name, $e);
if let Some(res) = $crate::eval($name, $e, || $cond) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

If true then we better add a test case that captures the expected behavior.

@gengliqi can you try adding a test case that shares mutable references between the two expressions and seeing if they worked previously but don't work after this patch?

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