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 python process name extraction. #11966

Merged
merged 1 commit into from
Apr 23, 2021

Conversation

jsirois
Copy link
Contributor

@jsirois jsirois commented Apr 23, 2021

Previously we grabbed the 1st 15 characters on Linux and, at least on
some versions of macOS, we didn't grab the process name at all, but the
actual name of the process executable instead. Since pantsd uses process
re-naming to leave a fingerprint it can use to detect its last recorded
pid has not been recycled to another process, the macOS case is
problematic. In our case, the process executable for pantsd is a Python
binary and processes with that as their executable are ubiquitous. This
defeats the pid recycling detection scheme.

Fix all this by grabbing the process name from the right place, only
falling back to the prior if there is a problem reading the process
command line (can happen for zombie processes at least). Add an
integration test that verifies we now read the full custom command line
and not a truncated version of it or the name of the process executable.

[ci skip-build-wheels]
[ci skip-rust]

Previous we grabbed the 1st 15 characters on Linux and, at least on some
versions of macOS we didn't grab the process name at all, but the actual
name of the process executable. Since pantsd uses process re-naming to
leave a fingerprint it can use its last recorded pid has not been
recycled to another process, the macOS case is problematic. In out case,
the process executable for pantsd is a Python binary and processes with
that as their executable are ubiquitous. This defeats the pid recycling
detection scheme.

Fix all this by grabbing the process name from the right place, only
falling back to the prior if there is a problem reading the process
command line (can happen for zombie processes at least). Add an
integration test that verifies we now read the full custom command line
and not a truncated version of it or the name of the process executable.

[ci skip-build-wheels]
[ci skip-rust]
@jsirois jsirois requested review from Eric-Arellano and tdyas April 23, 2021 00:21
@jsirois
Copy link
Contributor Author

jsirois commented Apr 23, 2021

This issue was discovered working #11922.

Copy link
Contributor

@Eric-Arellano Eric-Arellano left a comment

Choose a reason for hiding this comment

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

Thanks. Should this be cherry-picked?


import psutil
import pytest
from _pytest.tmpdir import TempdirFactory
Copy link
Contributor

Choose a reason for hiding this comment

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

Why use Pytest rather than contextutil.temporary_dir()?

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 mean - you're the guy who doesn't like nesting. I can't win! Do you really want me to use it? Just let me know the new trumping logic if so.

Copy link
Contributor

Choose a reason for hiding this comment

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

I can't win!

I'm sorry for the frustration :/

Do you really want me to use it?

The only thing that weirded me out is the private import. Otherwise, yeah, this would be great (but either approach fine)

--

It's okay to keep as is, these both work.

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'm going to leave as is here and merge before I dash out the door. I think the pytest tmp fixutres are more useful not because of the visual reason (flattening), but the practical reason that those tmpdirs hang around under /tmp/pytest-of-jsirois/pytest-current/... so tests are easier to debug.

Copy link
Contributor

Choose a reason for hiding this comment

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

Cool, that is what I was trying to get at - if you had forgotten we have .temporary_dir() vs using Pytest for a dedicated reason. Sg

@jsirois
Copy link
Contributor Author

jsirois commented Apr 23, 2021

Thanks. Should this be cherry-picked?

I don't think so. Wrapping the pid namespace is exceedingly unlikely and this bug has been out there since 1.x days with no direct reports of issues.

@jsirois jsirois merged commit bc4753c into pantsbuild:main Apr 23, 2021
@jsirois jsirois deleted the pantsd/process_name/fix branch April 23, 2021 00:38
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.

2 participants