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

Add option to delay propegating SIGINT to child process #1588

Merged
merged 2 commits into from
Jun 3, 2020

Conversation

jhesketh
Copy link

@jhesketh jhesketh commented May 21, 2020

Fixes #1497

Ctrl+C sends a SIGTERM to both tox and the running process, causing the
running process to receive the signal twice once tox passes it along.
This can often cancel or interfer with the process's cleanup.

Instead, add an option to allow a process to suicide before sending the
SIGTERM.

Co-Authored-By: Stefan H. Holek stefan@epy.co.at

Also includes a minor fix for correcting the location of the documentation for the existing timeout options: The interrupt_timeout and terminate_timeout options are set on the environment, not globally.

Contribution checklist:

  • wrote descriptive pull request text
  • added/updated test(s)
  • updated/extended the documentation
  • added relevant issue keyword in message body
  • added news fragment in changelog folder
    • fragment name: <issue number>.<type>.rst for example (588.bugfix.rst)
    • <type> is must be one of bugfix, feature, deprecation,breaking, doc, misc
    • if PR has no issue: consider creating one first or change it to the PR number after creating the PR
    • "sign" fragment with "by :user:<your username>"
    • please use full sentences with correct case and punctuation, for example: "Fix issue with non-ascii contents in doctest text files - by :user:superuser."
    • also see examples
  • added yourself to CONTRIBUTORS (preserving alphabetical order)

The interrupt_timeout and terminate_timeout options are set on the
environment, not globally.
@@ -160,22 +160,6 @@ Global settings are defined under the ``tox`` section as:
Name of the virtual environment used to create a source distribution from the
source tree.

.. conf:: interrupt_timeout ^ float ^ 0.3
Copy link
Member

Choose a reason for hiding this comment

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

Why move these?

Copy link
Author

Choose a reason for hiding this comment

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

This PR bundles up two commits. I can separate them out if needed, but it is explained in the earlier message:

Move timeout config options into correct section

The interrupt_timeout and terminate_timeout options are set on the
environment, not globally.

Copy link
Author

Choose a reason for hiding this comment

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

(I'll update the PR message at least)

jhesketh added a commit to jhesketh/rookcheck that referenced this pull request May 21, 2020
This requires a patch in tox that is currently WIP
tox-dev/tox#1588
@jhesketh
Copy link
Author

So the failing test (test_parallel_interrupt) is marked as flaky, and will fail (even without my patch) if you put a sleep at the beginning of Action.handle_interrupt. That likely explains the flakiness, but I am unsure where in the test it is expecting things to be cleaned up so quickly (adding sleeps or checking the processes has not helped in my debugging, so I'm probably missing something).

@jhesketh jhesketh requested a review from gaborbernat May 25, 2020 10:39
Copy link
Member

@gaborbernat gaborbernat left a comment

Choose a reason for hiding this comment

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

Sorry can't investigate this myself at the moment, and until the tests are passing we can't go ahead with this. Tets are passing on master.

@jheld
Copy link

jheld commented May 27, 2020

Are the master tests consistently passing?

@gaborbernat
Copy link
Member

Almost always.

@jheld
Copy link

jheld commented May 28, 2020

I'm confused. The docs suggest that tox already supports something like this.

interrupt_timeout, terminate_timeout.

Is that not what's being asked for?

@jhesketh
Copy link
Author

I'm confused. The docs suggest that tox already supports something like this.

interrupt_timeout, terminate_timeout.

Is that not what's being asked for?

The problem is that Ctrl+C will send a SIGINT to the foreground processes. This means that tox receives it along with pytest (or whatever it may be). Because tox then sends a SIGINT to the child processes it receives it twice. This goes unnoticed in most cases, but it often means that while pytest is cleaning up it receives another SIGINT and then aborts the cleanup.

This patch gives the running process a chance to exit before sending a SIGINT. If it hasn't exited, it'll receive a SIGINT from tox (which may be the first one it has received, or the second).

Fixes tox-dev#1497

Ctrl+C sends a SIGTERM to both Tox and the running process, causing the
running process to receive the signal twice once tox passes it along.
This can often cancel or interfer with the process's cleanup.

Instead, add an option to allow a process to suicide before sending the
SIGTERM.

Co-Authored-By: Stefan H. Holek <stefan@epy.co.at>
@jhesketh
Copy link
Author

jhesketh commented Jun 2, 2020

So I've set the default suicide timeout to 0.

This ensures that the behaviour has not changed from previously, and that programs get (at least one) SIGINT immediately. This also fixes the flaky test that appear to be sensitive to timing.

@gaborbernat gaborbernat merged commit 6360176 into tox-dev:master Jun 3, 2020
ssbarnea pushed a commit to ssbarnea/tox that referenced this pull request Apr 19, 2021
Co-Authored-By: Stefan H. Holek <stefan@epy.co.at>
Co-authored-by: Stefan H. Holek <stefan@epy.co.at>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Immediately forwarding Ctrl+C to child processes considered harmful
3 participants