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

avocado.main(): avoid an infinite fork loop bomb [v3] #985

Closed

Conversation

clebergnu
Copy link
Contributor

Because the current implementation of avocado.main() creates a job
and runs "sys.argv[0]" to implement standalone mode, it ends up
running itself over and over.

This simple proposed fix, prevents avocado.main() from running
itself again if called from itself. Since they are on different
processes, the mechanism chosen to do this is to set an environment
variable, that will be seen by the next process.

Also, by exiting from main() with an error code, the test first
level test will fail. This will let the user know that the chosen
approach (SIMPLE tests written in Python and calling main()) are
not worthy of a PASS.

This adresses issue #961.

Signed-off-by: Cleber Rosa crosa@redhat.com


Changes from v2:

  • Return an error code to signal that the used approach (calling main() is not ideal from a SIMPLE test).

Changes from v1:

  • Add error message to STDERR, warning that main() will exit to avoid a loop.

Because the current implementation of avocado.main() creates a job
and runs "sys.argv[0]" to implement standalone mode, it ends up
running itself over and over.

This simple proposed fix, prevents avocado.main() from running
itself again if called from itself. Since they are on different
processes, the mechanism chosen to do this is to set an environment
variable, that will be seen by the next process.

Also, by exiting from main() with an error code, the test first
level test will fail. This will let the user know that the chosen
approach (SIMPLE tests written in Python and calling main()) are
not worthy of a PASS.

This adresses issue avocado-framework#961.

Signed-off-by: Cleber Rosa <crosa@redhat.com>
@clebergnu clebergnu changed the title avocado.main(): avoid an infinite fork loop bomb avocado.main(): avoid an infinite fork loop bomb [v3] Jan 27, 2016
@clebergnu
Copy link
Contributor Author

@ldoktor I believe this is the behavior you were looking for. Can you take a look at it?

@ldoktor
Copy link
Contributor

ldoktor commented Jan 27, 2016

Very nice, thanks

@clebergnu
Copy link
Contributor Author

OK, so using process.run() is not a good idea because it can't handle certain situations such as the fork bomb.

Using --job-timeout, now that the nested main() behavior is to exit with error, is also not an option because of another bug which I documented here:

https://trello.com/c/H1AxryDp/568-bug-avocado-does-not-report-the-right-job-status-when-interrupted

Because of that, I implemented the timeout rather manually, using Python's subprocess module, and cleaning up the process (group) in case it doesn't finish in time.

@clebergnu
Copy link
Contributor Author

Closing in favor of #991

@clebergnu clebergnu closed this Jan 28, 2016
@lmr lmr removed the in progress label Jan 28, 2016
@clebergnu clebergnu deleted the avoid_fork_bomb_v3 branch May 4, 2016 21:14
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.

None yet

3 participants