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

fix(process): avoid leaking zombies and fds in detached processes #3379

Merged
merged 1 commit into from
Nov 8, 2024

Conversation

cgutman
Copy link
Collaborator

@cgutman cgutman commented Nov 8, 2024

Description

We were leaking detached child processes on Mac and Linux because we are expected to still wait on those with waitpid() in order to reap their entry in the process table. We will now do that when proc_t::running() is called (which happens regularly while streaming and periodically when clients poll for server info). This isn't a perfect solution but it's much better than the current situation today where all detached processes become zombies.

We were also leaking file descriptors into detached processes which could cause our log files and sockets to persist longer than expected.

Screenshot

Issues Fixed or Closed

Fixes #3378

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Dependency update (updates to dependencies)
  • Documentation update (changes to documentation)
  • Repository update (changes to repository files, e.g. .github/...)

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated the in code docstring/documentation-blocks for new or existing methods/components

@@ -241,22 +241,24 @@ namespace platf {

bp::child
run_command(bool elevated, bool interactive, const std::string &cmd, boost::filesystem::path &working_dir, const bp::environment &env, FILE *file, std::error_code &ec, bp::group *group) {
// clang-format off
Copy link
Collaborator Author

@cgutman cgutman Nov 8, 2024

Choose a reason for hiding this comment

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

clang-format gets confused by the boost::process syntax and thinks bp::std_in is a template class bp::std_in<bp::null, bp::std_out>

Copy link

codecov bot commented Nov 8, 2024

Codecov Report

Attention: Patch coverage is 0% with 11 lines in your changes missing coverage. Please review.

Project coverage is 11.05%. Comparing base (54ddf37) to head (627b64f).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
src/platform/linux/misc.cpp 0.00% 4 Missing ⚠️
src/platform/macos/misc.mm 0.00% 4 Missing ⚠️
src/process.cpp 0.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3379      +/-   ##
==========================================
- Coverage   11.11%   11.05%   -0.06%     
==========================================
  Files          75       99      +24     
  Lines       13204    17237    +4033     
  Branches     6084     8036    +1952     
==========================================
+ Hits         1467     1905     +438     
- Misses       9307    12783    +3476     
- Partials     2430     2549     +119     
Flag Coverage Δ
Linux 8.34% <0.00%> (?)
Windows 5.23% <ø> (ø)
macOS-13 13.62% <0.00%> (-0.02%) ⬇️
macOS-14 12.62% <0.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/process.cpp 2.68% <0.00%> (+0.53%) ⬆️
src/platform/linux/misc.cpp 9.23% <0.00%> (ø)
src/platform/macos/misc.mm 8.74% <0.00%> (-0.04%) ⬇️

... and 44 files with indirect coverage changes

Copy link

sonarqubecloud bot commented Nov 8, 2024

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.

Detached Processes launched by sunshine end up as zombies on linux after closing them
2 participants