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

Revert prev lint fix #1604

Merged
merged 7 commits into from
Jan 13, 2023
Merged

Revert prev lint fix #1604

merged 7 commits into from
Jan 13, 2023

Conversation

DonggeLiu
Copy link
Contributor

@DonggeLiu DonggeLiu commented Jan 9, 2023

Fixes #1594:

  1. Revert a previous lint fix (in Fix lint #1529) to avoid using with on subprocesses, as the context manager made local experiments fail to launch runner instances.
  2. Simplify the previous return statement, which was true by definition.

@DonggeLiu
Copy link
Contributor Author

@dliyanage @kdsjZh could you please test if this works? Thanks!
I am also running a new experiment on my local machine with this change, which seems to work so far.

@DonggeLiu
Copy link
Contributor Author

CI failed due to an expected lint error, as this PR reverts that lint fix.
I will handle that later.

@kdsjZh
Copy link

kdsjZh commented Jan 9, 2023

Now the runners container started, which seems work from my side! Thanks for the quick fix!

@DonggeLiu
Copy link
Contributor Author

Revert all lint fixes like with subprocess in #1529.
presubmit fails due to the following temporary fuzzers not being in fuzzer list:

  1. eclipser_aflplusplus
  2. neuzz
  3. fuzzolic_aflplusplus_z3
  4. fuzzolic_aflplusplus_fuzzy

@DonggeLiu
Copy link
Contributor Author

@jonathanmetzman A friendly gentle ping on this. Local experiments rely on this (fixes #1594).
I reckon the presubmit error is acceptable, because of the following reason:

Revert all lint fixes like with subprocess in #1529. presubmit fails due to the following temporary fuzzers not being in fuzzer list:

  1. eclipser_aflplusplus
  2. neuzz
  3. fuzzolic_aflplusplus_z3
  4. fuzzolic_aflplusplus_fuzzy

Copy link
Contributor

@jonathanmetzman jonathanmetzman left a comment

Choose a reason for hiding this comment

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

Sorry, but could you explain more?
what is this reverting and how does this fix a problem? THe changed code seems broken IMO

common/gcloud.py Outdated
return new_process.ProcessResult(0, '', False)
# pylint: disable=consider-using-with
subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
return new_process.ProcessResult(0, '', False).retcode == 0
Copy link
Contributor

Choose a reason for hiding this comment

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

This will always be true wont it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, maybe I can also fix it by adding ==0 to return new_process.ProcessResult(0, '', False).

Copy link
Contributor Author

@DonggeLiu DonggeLiu Jan 9, 2023

Choose a reason for hiding this comment

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

I don't think the new code (after revert) will always be true.
For example, it will be false if the process fails and returns a non-zero value, right?

Copy link
Contributor

@aeflores aeflores Jan 10, 2023

Choose a reason for hiding this comment

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

The way it was before using a context manager (before a6a5a9a) was:

subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
return new_process.ProcessResult(0, '', False)

That indeed does not check anything about Popen. new_process.ProcessResult(0, '', False) is just creating a named tuple (see definition here https://github.com/google/fuzzbench/blob/master/common/new_process.py#L67). There is no connection between that line and the call to Popen.

The important fix here though is to stop using the context manager. As per the documentation (https://docs.python.org/3/library/subprocess.html?highlight=popen#subprocess.Popen)

Popen objects are supported as context managers via the with statement: on exit, standard file descriptors are closed, and the process is waited for.

Using a context manager closes file descriptors and waits for the process to terminate, which is probably what is causing problems. This code probably needs to start the process, but not wait for its termination.

My suggestion would be:

subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
return True

If we want to be extra careful, we should check that the subprocess is created successfully, but I think we will get an exception if that were not the case anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, @aeflores!
Yeah, your suggestion is cleaner as the old return statement is trivially true.
I've fixed it accordingly : )

stderr=subprocess.STDOUT):
return new_process.ProcessResult(0, '', False)
# pylint: disable=consider-using-with
subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this does anything to check if the command succeeded.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It checks the return status of the command in the next line.

Copy link
Contributor

@oliverchang oliverchang Jan 13, 2023

Choose a reason for hiding this comment

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

This seems like the same behaviour as before: https://github.com/google/fuzzbench/pull/1529/files#diff-f61c598f4891541e693644bbc9016e5841fcddc986ea967eb3e192586a8c57deL133

The previous return was a no-op that would've always returned True (side note: is this behaviour actually correct?)

    subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
    return new_process.ProcessResult(0, '', False).retcode == 0

@alan32liu would be good to make this more explicit in the PR description in the future to make it clearer to reviewers :)

@@ -91,8 +91,8 @@ def run_neuzz(input_corpus,
'python2', './nn.py', '--output-folder', afl_output_dir, target_binary
]
print('[run_neuzz] Running command: ' + ' '.join(command))
with subprocess.Popen(command, stdout=output_stream, stderr=output_stream):
pass
# pylint: disable=consider-using-with
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this patch changes too much. I think with usage didn't make sense in the first location, but I don't see why you would change these other ones. I think it makes sense here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, I think I should have considered this case by case:

  1. Should use context manager (with) to wait for the process :
    • Here, to enable asan (probably can remove sleep, but I suppose it is better to leave it in this PR?).
  2. Should not use context manager (with):
    • gcloud, to fix the bug in local experiments.
  3. Neutral:
    • All others, using context manager has a neutral effect.

I am inclined to not use with in 3, because it looks cleaner, and it was that way before I attempt to use with to fix linter errors.
@jonathanmetzman what would you think? Thanks!

Copy link
Contributor

Choose a reason for hiding this comment

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

I think you should get rid of it in gcloud.py.
I think the other cases should be unchanged. but I'm not sure about them, maybe try a make test-run-... to check them. Either way these files are unimportant so just fix gcloud for now and ignore these please.
Thanks!

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 see!
Done, thanks!

stderr=subprocess.STDOUT):
return new_process.ProcessResult(0, '', False)
# pylint: disable=consider-using-with
subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
Copy link
Contributor

@oliverchang oliverchang Jan 13, 2023

Choose a reason for hiding this comment

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

This seems like the same behaviour as before: https://github.com/google/fuzzbench/pull/1529/files#diff-f61c598f4891541e693644bbc9016e5841fcddc986ea967eb3e192586a8c57deL133

The previous return was a no-op that would've always returned True (side note: is this behaviour actually correct?)

    subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
    return new_process.ProcessResult(0, '', False).retcode == 0

@alan32liu would be good to make this more explicit in the PR description in the future to make it clearer to reviewers :)

@Navidem
Copy link
Contributor

Navidem commented Jan 13, 2023

With this PR, I do not get No snapshot data warning, but am getting this:
WARNING:root:Corpus not found for cycle: 3. Extras: {'fuzzer': 'centipede', 'benchmark': 'libpng-1.6.38', 'trial_id': '35', 'cycle': '3'}

Copy link
Contributor

@Navidem Navidem left a comment

Choose a reason for hiding this comment

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

LGTM

@Navidem
Copy link
Contributor

Navidem commented Jan 13, 2023

I think we can merge this.

@DonggeLiu DonggeLiu merged commit 2749078 into master Jan 13, 2023
@DonggeLiu DonggeLiu deleted the fix_local_exp branch January 13, 2023 02:33
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.

trials not launching in local experiment
6 participants