Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Manually set a process title when using load #4589

Closed
wants to merge 1 commit into from

Conversation

yob
Copy link
Contributor

@yob yob commented May 19, 2016

With bundler 1.11.2, the process name for rake tasks include the task name:

$ bundle exec rake foo:bar

$ ps ux | grep rake
 user         1758 62.2  2.4 385816 202032 pts/3   Sl+  16:16   0:04 ruby /usr/bin/rake foo:bar

On bundler 1.12.0, the process name changed:

$ bundle exec rake foo:bar

$ ps ux | grep rake
 user         1758 62.2  2.4 385816 202032 pts/3   Sl+  16:16   0:04 /usr/bin/rake

The change in behaviour is caused by bundler 1.12 using load (instead of exec) where
possible, and manually using $0= to set the command name. Unfortunately, that also alters
the process title visible with ps, and using Process.setproctitle can help reverse that.

The tests are green on my ruby 2.3.1/linux system, but I haven't run them on older rubies or non-linux environments. I'm assuming they'll need some modifications to be maximally compatible, but let's see what happens.

See also: #4488

@@ -70,6 +71,14 @@ def kernel_load(file, *args)
abort "#{e.class}: #{e.message}\n #{backtrace.join("\n ")}"
end

def process_title(file, *args)
Copy link
Member

Choose a reason for hiding this comment

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

no reason to splat *args here

With bundler 1.11.2, the process name for rake tasks looked like this:

   $ bundle exec rake foo:bar

   $ ps ux | grep rake
    user         1758 62.2  2.4 385816 202032 pts/3   Sl+  16:16   0:04 ruby /usr/bin/rake foo:bar

On bundler 1.12.0, the process name changed:

   $ bundle exec rake foo:bar

   $ ps ux | grep rake
    user         1758 62.2  2.4 385816 202032 pts/3   Sl+  16:16   0:04 /usr/bin/rake

The change in behaviour is caused by bundler 1.12 using `load` (instead of `exec`) where
possible, and manually using `$0=` to set the command name. Unfortunately, that also alters
the process title visible with ps, and using Process.setproctitle can help reverse that
@yob
Copy link
Contributor Author

yob commented Jun 11, 2016

Hi all,

I haven't had much time to re-visit this, and we've since found a workaround for our use case.

I'm happy to try and polish this into something that's mergable, but I'll need a bit more guidance on how to proceed. It seems Process.setproctitle won't meet backward compatibility requirements. Should I consider making the fix only apply to ruby >= 2.1?

@indirect
Copy link
Member

indirect commented Jul 6, 2016

@yob we typically use checks like if Process.respond_to?(:setproctitle) when we need something to continue to work (without the new feature) on older Rubies.

@segiddins
Copy link
Member

I've manually addressed the comments on this in #4863

homu added a commit that referenced this pull request Aug 11, 2016
Manually set a process title when using load

Closes #4589.
See #4852.
homu added a commit that referenced this pull request Aug 11, 2016
Manually set a process title when using load

Closes #4589.
See #4852.
@homu homu closed this in #4863 Aug 11, 2016
@homu
Copy link
Contributor

homu commented Aug 11, 2016

☔ The latest upstream changes (presumably #4863) made this pull request unmergeable. Please resolve the merge conflicts.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants