Skip to content

cancellation handler #4173

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

Merged
merged 2 commits into from
Mar 11, 2022
Merged

cancellation handler #4173

merged 2 commits into from
Mar 11, 2022

Conversation

tomerd
Copy link
Contributor

@tomerd tomerd commented Feb 24, 2022

motivation: allow clients of SwiftPM to cancel background activities

changes:

  • introduce new "cancellator" utility that is a registry for cancellation handlers
  • use the "cancellator" instead of ProcessSet to manage the cancellation of active processes (eg git, tests) and build system
  • add cancel method to GitRepositoryProvider protocol so that it can be interuppted
  • add cancel methods to RepositoryManager, RegistryDownloadManager and HTTPClient so that it can be interrupted
  • change workspace initializer to take a terminator so that CLI and other consumer of libSwiftPM can interrupt
  • register interruption points mentioned above in workspace
  • adjust related call sites, ie CLI signal handler now uses the workspace terminator to interrupt
  • add tests

rdar://64900054
rdar://63723896

@tomerd tomerd added the WIP Work in progress label Feb 24, 2022
@tomerd tomerd changed the title termination handler [wip] termination handler Feb 24, 2022
@tomerd tomerd force-pushed the feature/interrupt branch 4 times, most recently from 6ff0d9a to ff62b8b Compare February 24, 2022 05:39
@tomerd tomerd force-pushed the feature/interrupt branch 3 times, most recently from 05e5d6f to 1ddac2a Compare February 24, 2022 23:02
@tomerd tomerd force-pushed the feature/interrupt branch 2 times, most recently from 4eef326 to f99b761 Compare February 26, 2022 01:26
@@ -430,8 +424,7 @@ public class SwiftTool {

// Terminate all processes on receiving an interrupt signal.
DefaultPluginScriptRunner.cancelAllRunningPlugins()
Copy link
Contributor

Choose a reason for hiding this comment

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

Looking forward to replacing this line with the new API you're adding (in a follow-on PR)! :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

happy to try and do a follow up PR for that, need to learn more about how plugin cancellation could work

Copy link
Contributor

@abertelrud abertelrud left a comment

Choose a reason for hiding this comment

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

This looks great!

@tomerd tomerd force-pushed the feature/interrupt branch 2 times, most recently from 5112b06 to 4aece57 Compare March 1, 2022 02:33
@tomerd tomerd force-pushed the feature/interrupt branch 3 times, most recently from d529594 to 3fc7a50 Compare March 1, 2022 19:46
@tomerd tomerd changed the title [wip] termination handler termination handler Mar 1, 2022
@tomerd tomerd changed the title termination handler cancellation handler Mar 1, 2022
@tomerd
Copy link
Contributor Author

tomerd commented Mar 1, 2022

@swift-ci please smoke test

@tomerd tomerd added ready Author believes the PR is ready to be merged & any feedback has been addressed and removed WIP Work in progress labels Mar 1, 2022

public typealias CancellationHandler = (DispatchTime) throws -> Void

public class Cancellator: Cancellable {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Originally was named "terminator" which is cute but less accurate. Happy to take suggestions for a nicer name

@tomerd
Copy link
Contributor Author

tomerd commented Mar 1, 2022

@swift-ci please smoke test

@tomerd tomerd force-pushed the feature/interrupt branch from e42de3a to a322bf7 Compare March 1, 2022 23:18
@tomerd
Copy link
Contributor Author

tomerd commented Mar 1, 2022

@swift-ci please smoke test

@tomerd
Copy link
Contributor Author

tomerd commented Mar 2, 2022

@abertelrud this is ready for review

@compnerd could you help make sure this builds / works on Windows

Copy link
Member

@compnerd compnerd left a comment

Choose a reason for hiding this comment

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

Delta: ~30KiB
Basics.dll: 276,992 -> 297,984
Commands.dll: 5,531,648 -> 5,532,672
Workspace.dll: 1,356,800 -> 1,3564,992

I'll play around with it itself to see if there are any issues, though I suspect not.

@tomerd
Copy link
Contributor Author

tomerd commented Mar 2, 2022

@swift-ci please smoke test

@tomerd tomerd self-assigned this Mar 3, 2022
@tomerd tomerd force-pushed the feature/interrupt branch from c961e2c to 0041ad0 Compare March 4, 2022 00:43
@tomerd
Copy link
Contributor Author

tomerd commented Mar 4, 2022

@swift-ci please smoke test

@tomerd tomerd force-pushed the feature/interrupt branch from 0041ad0 to c138638 Compare March 5, 2022 01:03
@tomerd
Copy link
Contributor Author

tomerd commented Mar 5, 2022

@swift-ci please smoke test

}

/*
Copy link
Contributor

Choose a reason for hiding this comment

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

left-over debugging?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ugh yes

@tomerd tomerd force-pushed the feature/interrupt branch from c138638 to ead18a6 Compare March 7, 2022 19:32
tomerd added 2 commits March 7, 2022 11:32
motivation: allow clients of SwiftPM to terminate background activities

changes:
* introduce new terminator class that is a registry for termination handlers
* use the terminator instad of ProcessSet to manage the termination of active processes (eg git, tests) and build system
* add cancel method to GitRepositoryProvider protocol so that it can be interuppted
* add cancel methods to RepositoryManager, RegistryDownloadManager and HTTPClient so that it can be interuppted
* change workspace initializer to take a terminator so that CLI and other consumer of libSwiftPM can interrupt
* register intrupption points mentioned above in workspace
* adjust related call sites, ie CLI signal handler now uses the workspace terminator to interuupt
* add tests

rdar://64900054
rdar://63723896
@tomerd tomerd force-pushed the feature/interrupt branch from ead18a6 to 680e9ea Compare March 7, 2022 19:32
@tomerd
Copy link
Contributor Author

tomerd commented Mar 7, 2022

@swift-ci please smoke test

@tomerd tomerd merged commit a1c8482 into swiftlang:main Mar 11, 2022
@compnerd
Copy link
Member

This seemed to have dropped the Windows fixes and has broken the windows build: https://ci-external.swift.org/job/oss-swift-windows-toolchain-x86_64-vs2019/1130/console

compnerd added a commit that referenced this pull request Mar 12, 2022
compnerd added a commit that referenced this pull request Mar 12, 2022
tomerd added a commit that referenced this pull request Mar 13, 2022
@tomerd tomerd mentioned this pull request Mar 13, 2022
tomerd added a commit that referenced this pull request Mar 13, 2022
* Revert "Revert "cancellation handler (#4173)""

This reverts commit c948a86.

* windows fix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready Author believes the PR is ready to be merged & any feedback has been addressed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants