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

Rename Process kill methods to signal #8642

Closed

Conversation

jan-zajic
Copy link
Contributor

As suggested by @ysbaddaden in #8518 and further discussed in draft #8536 rename Process#kill(Signal) to Process#signal(Signal) that we can eventually implement on Windows (if needed) with a deprecation notice. The name kill is confusing as it can means two things - send signal to process, or send signal kill (9) to process when argument ommited. But currently default behavior of kill method without providing signal argument is to send term signal to process (simulates posix behavior of kill command, but we need to remove POSIXisms of apis to become realy portable imho).

@bcardiff
Copy link
Member

bcardiff commented Jan 2, 2020

Please keep Process#kill with a @[Deprecated("Use #signal instead")] annotation.
And keep a minimal spec that uses #kill

@Blacksmoke16
Copy link
Member

Blacksmoke16 commented Jan 2, 2020

I'd also advocate for including something like, and will be removed in Crystal 0.34.0 so that there is an actual expectation of when it will/should be removed.

spec/std/process_spec.cr Outdated Show resolved Hide resolved
@jan-zajic
Copy link
Contributor Author

Either way i think it's better that renamed signal method should not have default value, so i removed it. Because of code readability - with process.signal without argument it's very unclear what it does.

@jan-zajic
Copy link
Contributor Author

btw @bcardiff build now fail on some crazy error (in more PRs, not only this):

.build/std_spec: relocation error: .build/std_spec: symbol gmon_start version GLIBC_2.2.5 not defined in file libpthread.so.0 with link time reference

@bcardiff
Copy link
Member

bcardiff commented Jan 2, 2020

@jan-zajic Yeah, it should be fixed by #8641

src/process.cr Show resolved Hide resolved
src/process.cr Outdated Show resolved Hide resolved
src/process.cr Outdated Show resolved Hide resolved
src/process.cr Outdated Show resolved Hide resolved
src/process.cr Outdated Show resolved Hide resolved
jan-zajic added a commit to jan-zajic/crystal that referenced this pull request Jan 3, 2020
Co-Authored-By: Benoit de Chezelles <bew@users.noreply.github.com>
@jan-zajic
Copy link
Contributor Author

@RX14 , @straight-shoota updated according to reviews.

src/process.cr Outdated Show resolved Hide resolved
Copy link
Member

@straight-shoota straight-shoota left a comment

Choose a reason for hiding this comment

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

The changes from process.kill to process.signal Signal::Term are somewhat counterproductive.
#kill without arguments is going to become #terminate in #8536.

I'd suggest to introduce #terminate and #interrupt already in this PR. It makes sense because they're portable successors to #kill and the different uses can be replaced appropriately.

As a bonus, #8536 would truly be only a refactor and neither add nor change any features.

@@ -161,7 +161,7 @@ module Crystal::Playground
@logger.info "Code execution killed (session=#{@session_key}, filename=#{@running_process_filename})."
@process = nil
File.delete @running_process_filename rescue nil
process.kill rescue nil
process.signal(::Signal::TERM) rescue nil
Copy link
Member

Choose a reason for hiding this comment

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

This one.

src/process.cr Outdated
@@ -193,7 +199,7 @@ class Process
$? = process.wait
value
rescue ex
process.kill
process.signal Signal::TERM
Copy link
Member

Choose a reason for hiding this comment

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

And this one.

@jan-zajic
Copy link
Contributor Author

jan-zajic commented Jan 8, 2020

@straight-shoota I'm all for it. But that assumes we will agree on names of that methods. I still don't know any opinion of others. I'am currently for #terminate and #destroy as shown in new commit.

The options considered so far are (in order gracefully, force shutdown):

  • #terminate_gracefully, #terminate_immediately
  • #terminate, #kill
  • #terminate, #interrupt
  • #terminate, #destroy

So please vote! @straight-shoota, @RX14, @ysbaddaden, @j8r, @Sija, @bew, @bcardiff ping. If I forgot someone please let them know.

@straight-shoota
Copy link
Member

The method to terminate a process is commonly named kill in most APIs, which is named after the homonymous unix program.
I think it's best to follow that line and keep the name. The existing overload of #kill without arguments can stay, only the behaviour should be changed to send SIGKILL on Posix. This is a breaking change, but not very relevant.

Let's not bother with an alternative method for graceful termination in this PR. Having separate methods for sending signals and terminating a process is sufficient. If you need graceful termination, you can easily send SIGTERM manually. Whether we should have a dedicated method for this should be a separate discussion to not prolong this PR even more.

@Sija
Copy link
Contributor

Sija commented Jan 8, 2020

kill is a commonly used term as @straight-shoota mentioned, so my vote goes for:

#terminate, #kill

@j8r
Copy link
Contributor

j8r commented Jan 8, 2020

The kill man is: kill - send a signal to a process.

I prefer Process#send_signal.

@RX14
Copy link
Contributor

RX14 commented Jan 8, 2020

Please let's not use kill, it's confusing with the existing API.

signal should be used for sending signals

terminate should terminate the process

interrupt will interrupt the process and ask it to shut down

i like the current naming, and i'd prefer for it to stay

@Sija
Copy link
Contributor

Sija commented Jan 8, 2020

Please let's not use kill, it's confusing with the existing API.

@RX14 How come? It sends KILL signal, as you would expect from the naming...

@straight-shoota
Copy link
Member

it's confusing with the existing API.

I wouldn't worry about that. We need to focus on the best API for the future.
It seems literally everyone names this "kill", so I doubt we should settle for something else.

@RX14
Copy link
Contributor

RX14 commented Jan 8, 2020

No, kill is confusingly for sending signals, with the default being SIGTERM.

So would you rather have kill send SIGTERM and terminate send SIGKILL?

@RX14
Copy link
Contributor

RX14 commented Jan 8, 2020

Actually this is all too confusing the only interface should be #signal as I originally said.

@Sija
Copy link
Contributor

Sija commented Jan 8, 2020

@RX14 What's confusing about calling Process#kill, which in turn would send Signal::KILL signal...? For my taste it can't be clearer than that.

Process#terminate => Process#signal(Signal::TERM)
Process#kill => Process#signal(Signal::KILL)

@straight-shoota
Copy link
Member

straight-shoota commented Jan 8, 2020

No, kill is confusingly for sending signals, with the default being SIGTERM.

The default should be SIGKILL. Even if it was SIGTERM, that's merely an implementation detail.
Process#kill just provides a generic, high level interface to terminate a process. The exact implementation and behaviour is obviously platform specific, but we should try to make it as similar as possible across platforms.

Simply having everyone call signal(:kill) is not sufficient. It just mimics the POSIX API and is neither generic nor idiomatic. There is an explicit method to spawn a process (which is already at a very high level of abstraction) and there should also be an explicit method to terminate a process at the same level of abstraction.
(We can certainly make signal(:kill) work on windows as well)

@RX14
Copy link
Contributor

RX14 commented Jan 9, 2020

We can't use the #kill name right now because #kill with no args means SIGTERM.

There must be at least one release where #kill is removed, before we reuse it's name with a different semantics.

@RX14
Copy link
Contributor

RX14 commented Jan 9, 2020

How about introducing just #terminate in this PR which sends SIGTERM, then after #kill is gone, we can add it back sending SIGKILL. So this PR would just have #signal and #terminate?

@jan-zajic
Copy link
Contributor Author

jan-zajic commented Jan 9, 2020 via email

@straight-shoota
Copy link
Member

Sure, we can do that. But IMO we don't need a full deprecation cycle just to change the implementation of Process#kill from SIGTERM to SIGKILL. That seems to be an overkill. The method still works the same way terminating a process. It only makes a difference when the process actually traps SIGTERM.

However I'm still not sure we actually want a #terminate method for signalling graceful termination.


process.terminate
process.exists?.should be_true
process.terminated?.should be_false
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems like a race condition to me. If the program gets rescheduled between the terminate call and the exists? check then this spec will fail. I suspect that running this test in a loop on a loaded machine will already fail.

I'm not sure there's an appropriate way to test this.

@RX14
Copy link
Contributor

RX14 commented Jan 10, 2020

This is OK for me to merge except for the race condition in the spec suite

@straight-shoota
Copy link
Member

@jan-zajic Are you still up for this addressing the above comment?

@jan-zajic
Copy link
Contributor Author

@straight-shoota ok i look at it in few days

@oprypin
Copy link
Member

oprypin commented Apr 3, 2020

Was write access given to the branch? Could someone simply remove this spec and merge the PR?

@oprypin
Copy link
Member

oprypin commented Apr 3, 2020

Mhm, the merge is non-trivial.

I have merged it and I'm ready to send a new PR.
master...oprypin:winkill

I think such a PR, if merged, would show me as the primary author, which is not ideal.

@oprypin
Copy link
Member

oprypin commented Apr 3, 2020

@jan-zajic, could you give some input?
Would you be able to keep pushing this forward?
Do you want to hand over the ownership of this somehow?
Are you OK with someone else re-creating a pull request with your commits?

@jan-zajic
Copy link
Contributor Author

@oprypin unfortunately i don't have time right now to be able to keep pushing this forward.. So i'm ok with your help, as long as you keep my original work (to some point that make sense), so my original effort will not be wasted.. Last time i put a lot of effort into this, but but we got lost in discussions that led nowhere.

@jan-zajic jan-zajic closed this Apr 8, 2020
@jan-zajic
Copy link
Contributor Author

Closed in favor of #9006

@oprypin oprypin mentioned this pull request Apr 10, 2020
22 tasks
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.

10 participants