foreman icon indicating copy to clipboard operation
foreman copied to clipboard

Run processes in new process groups, kill process group instead of process

Open dentarg opened this issue 4 years ago • 9 comments

This is https://github.com/ddollar/foreman/pull/723 but rebased against master today. Credit to @davishmcclurg for suggesting those changes in the first place.

Some processes are getting orphaned when running Foreman with JRuby. Creating a new pgroup allows them all to be killed together.

I believe the issue is related to how JRuby handles Dir.chdir by creating a shell process: sh -c 'cd /chdir/target; ${command}'. That causes a second process to be created that won't get cleaned up by killing the parent.

I think this change also addresses #779. It makes Foreman match what Honcho does, and Honcho does not exhibit the problem shown in #779.

Close #779

(Some additional background: There was an earlier PR #528 that did half of what this PR does, https://github.com/ddollar/foreman/issues/525 was closed after that was merged, but then the PR was reverted after a few days, could not find the reason for that).

dentarg avatar Jun 26 '21 18:06 dentarg

cc @ddollar this is my only day to day pain with foreman.

Would love getting this get merged.

domenkozar avatar Oct 31 '21 16:10 domenkozar

@domenkozar I think it's time to fork and release a new gem. The issue this PR addresses drives me nuts as well and it's getting close to a year for a branch with no conflicts.

sjjbirch avatar Aug 09 '22 07:08 sjjbirch

I maintain way too many OSS projects, but if you decide to go for it, I'm happy to test.

domenkozar avatar Aug 09 '22 08:08 domenkozar

Ping @ddollar

baelter avatar Oct 28 '22 08:10 baelter

foreman forked: https://github.com/spinels/overman, https://rubygems.org/gems/overman

The published version is current master (a5f9b78) + this PR. The executable is called overman so you can have both gems installed at the same time. You can also uninstall foreman and make foreman an alias to overman.

Please try it!

dentarg avatar Oct 28 '22 13:10 dentarg

This PR makes it better, but it's not enough, see https://github.com/spinels/overman/issues/2.

oleg-vinted avatar May 09 '23 07:05 oleg-vinted

For what it's worth, neither goreman, forego, nor overmind exhibit this behavior.

oleg-vinted avatar May 09 '23 08:05 oleg-vinted

For what it's worth, I was running into orphaned children in some situations after a Ctrl+C on foreman, and switching to overman resolved that.

msakrejda avatar Jul 10 '24 19:07 msakrejda

Scratch that: it resolved the issue on my system, but some colleagues ran into weird behavior with some spawned processes (specifically the Vite dev server).

msakrejda avatar Jul 19 '24 19:07 msakrejda