Skip to content

Add support for HUP, USR1, USR2 signals #86

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 11 commits into from
Mar 13, 2021

Conversation

hassila
Copy link
Contributor

@hassila hassila commented Mar 12, 2021

Motivation:
Some servers want to support customised handling of signals except for simply shutting down.

Added support for USR1/USR2 signal traps for (#64) - extended trap() signature with one more optional argument to allow for signal handler to be run multiple times with usage like this:

let alrmDispatchSourceSignal = ServiceLifecycle.trap(signal: ServiceLifecycle.Signal.USR1, handler: { signal in
	    print("signal \(signal)")
	}, cancelAfterTrap: false)```

Existing usage of .trap() is unaffected.

Possibly additional signals (HUP?) should be added too.

Changes:
Added USR1/USR2 to Signal struct to allow for trapping them.
Changed .trap() signature to allow for signal handlers to be run multiple times without reregistration.

hassila and others added 4 commits March 12, 2021 08:24
Updated the dependency to use .product as instructed by SPM when trying to follow the instructions.
Updated target dependency example
@swift-server-bot
Copy link

Can one of the admins verify this patch?

6 similar comments
@swift-server-bot
Copy link

Can one of the admins verify this patch?

@swift-server-bot
Copy link

Can one of the admins verify this patch?

@swift-server-bot
Copy link

Can one of the admins verify this patch?

@swift-server-bot
Copy link

Can one of the admins verify this patch?

@swift-server-bot
Copy link

Can one of the admins verify this patch?

@swift-server-bot
Copy link

Can one of the admins verify this patch?

Motivation:

Adding support for capturing HUP too in addition to USR1/USR2.

Modifications:

Added HUP signal, added descriptive strings for new signals.

Result:
HUP and USR signals available.
@ktoso
Copy link
Contributor

ktoso commented Mar 12, 2021

@swift-server-bot test this please

@hassila
Copy link
Contributor Author

hassila commented Mar 12, 2021

I added HUP too.

@hassila hassila changed the title Add support for USR1/2 signals Add support for HUP, USR1, USR2 signals Mar 12, 2021
@tomerd
Copy link
Contributor

tomerd commented Mar 12, 2021

@tomerd tomerd added this to the 1.0.0-alpha.7 milestone Mar 12, 2021
@@ -177,11 +177,13 @@ extension ServiceLifecycle {
/// - signal: The signal to trap.
/// - handler: closure to invoke when the signal is captured.
/// - returns: a `DispatchSourceSignal` for the given trap. The source must be cancelled by the caller.
public static func trap(signal sig: Signal, handler: @escaping (Signal) -> Void, on queue: DispatchQueue = .global()) -> DispatchSourceSignal {
public static func trap(signal sig: Signal, handler: @escaping (Signal) -> Void, on queue: DispatchQueue = .global(), cancelAfterTrap: Bool = true) -> DispatchSourceSignal {
Copy link
Contributor

Choose a reason for hiding this comment

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

I prefer we make cancelAfterTrap default to true and change the internal call to set it to false, so the API is nicer to use from a user point of view

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Definitely agree, +1. Only reason was reflex to not affect possible other users of API. Will fix.

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 changed default in 8d379dc - missed mentioning it in commit message.

Copy link
Contributor

@tomerd tomerd left a comment

Choose a reason for hiding this comment

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

one comment re. default and formatting issues

hassila added 2 commits March 12, 2021 21:44
Motivation:

Trying to adhere to code standards.

Modifications:

Removing tabs replacing with whitespace.

Result:

Adhering to soundness.sh, adding documentation.
@hassila
Copy link
Contributor Author

hassila commented Mar 12, 2021

@tomerd I tried to run soundness and failed:
jocke@solid /V/j/l/swift-service-lifecycle (hassila-usr-signals)> scripts/soundness.sh
=> Checking for unacceptable language... okay.
=> Checking linux tests... okay.
=> Checking format... ⏎ jocke@solid /V/j/l/swift-service-lifecycle (hassila-usr-signals) [127]>

Assuming the return keys references CRLF issues (just a guess) but nothing obvious (file just edit on macOS and Linux with emacs/xcode). I have removed the tabs that were there previously though.

Committed without tabs and added some documentation.

@hassila
Copy link
Contributor Author

hassila commented Mar 12, 2021

Ok, I have tried to clean whitespace as much as possible, but I get this weird output from soundness.sh which is difficult to guess the purpose of:

jocke@swift511 ~/l/swift-service-lifecycle (hassila-usr-signals)> scripts/soundness.sh
=> Checking for unacceptable language... okay.
=> Checking linux tests... okay.
=> Checking format... ^J                 
jocke@swift511 ~/l/swift-service-lifecycle (hassila-usr-signals) [127]> 

@tomerd
Copy link
Contributor

tomerd commented Mar 12, 2021

@swift-server-bot test this please

@tomerd
Copy link
Contributor

tomerd commented Mar 12, 2021

Ok, I have tried to clean whitespace as much as possible, but I get this weird output from soundness.sh which is difficult to guess the purpose of:

looks like formatting is still incorrect, run swiftformat . to have it format the project for you

@hassila
Copy link
Contributor Author

hassila commented Mar 12, 2021

I tried swift format, but it did changes like:

-    public static func eventLoopFuture(_ future: @escaping () -> EventLoopFuture<Void>) -> LifecycleHandler {
+    static func eventLoopFuture(_ future: @escaping () -> EventLoopFuture<Void>) -> LifecycleHandler {

will look at it bit more, but seemed a bit aggressive there :-)

@tomerd
Copy link
Contributor

tomerd commented Mar 12, 2021

make sure you use swiftformat not swift-format: brew install swiftformat

@hassila
Copy link
Contributor Author

hassila commented Mar 12, 2021

I downloaded and built this one on Linux: https://github.com/nicklockwood/SwiftFormat - not the right one?

@hassila
Copy link
Contributor Author

hassila commented Mar 12, 2021

jocke@swift511 ~/l/swift-service-lifecycle (hassila-usr-signals) [1]> swiftformat --version
0.47.12

@tomerd
Copy link
Contributor

tomerd commented Mar 12, 2021

tool looks fine - I think ci uses 0.44.6

you can see the formatting issue in the log: https://ci.swiftserver.group/job/swift-service-lifecycle-soundness-prb/189/console

@hassila
Copy link
Contributor Author

hassila commented Mar 12, 2021

Thanks, I couldn't find that log. Pushed fixes for those now. Seems the new version of swift formatter does a bit more, I will try to fetch 0.44.6 to try to get same output (until CI is updated).

@hassila
Copy link
Contributor Author

hassila commented Mar 12, 2021

soundness.sh now passed for formatting at least, thanks for the patience answering questions.

@tomerd
Copy link
Contributor

tomerd commented Mar 12, 2021

@swift-server-bot test this please

@tomerd
Copy link
Contributor

tomerd commented Mar 12, 2021

@hassila
Copy link
Contributor Author

hassila commented Mar 13, 2021

Fixed in 265fb15.

@tomerd
Copy link
Contributor

tomerd commented Mar 13, 2021

@swift-server-bot test this please

@hassila
Copy link
Contributor Author

hassila commented Mar 13, 2021

(and installed exact version of swiftformat as used by CI for the future - 0.44.6 doesn't touch as aggressively and can and will now be used... thanks.)

@tomerd tomerd merged commit ac8ba89 into swift-server:main Mar 13, 2021
@tomerd
Copy link
Contributor

tomerd commented Mar 13, 2021

thanks @hassila

@hassila hassila deleted the hassila-usr-signals branch March 13, 2021 04:44
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.

4 participants