-
Notifications
You must be signed in to change notification settings - Fork 273
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
Revert prev lint fix #1604
Conversation
@dliyanage @kdsjZh could you please test if this works? Thanks! |
CI failed due to an expected lint error, as this PR reverts that lint fix. |
Now the runners container started, which seems work from my side! Thanks for the quick fix! |
Revert all lint fixes like
|
@jonathanmetzman A friendly gentle ping on this. Local experiments rely on this (fixes #1594).
|
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.
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 |
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.
This will always be true wont it?
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.
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.
Hmm, maybe I can also fix it by adding ==0
to return new_process.ProcessResult(0, '', False)
.
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.
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?
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.
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.
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.
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) |
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.
I don't think this does anything to check if the command succeeded.
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.
It checks the return status of the command in the next line.
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.
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 :)
fuzzers/neuzz/fuzzer.py
Outdated
@@ -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 |
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.
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.
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.
Right, I think I should have considered this case by case:
- Should use context manager (
with
) to wait for the process :- Here, to enable
asan
(probably can removesleep
, but I suppose it is better to leave it in this PR?).
- Here, to enable
- Should not use context manager (
with
):gcloud
, to fix the bug in local experiments.
- 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!
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.
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!
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.
I see!
Done, thanks!
This reverts commit e98c11a.
stderr=subprocess.STDOUT): | ||
return new_process.ProcessResult(0, '', False) | ||
# pylint: disable=consider-using-with | ||
subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
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.
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 :)
With this PR, I do not get |
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.
LGTM
I think we can merge this. |
Fixes #1594:
with
on subprocesses, as the context manager made local experiments fail to launch runner instances.