cpython icon indicating copy to clipboard operation
cpython copied to clipboard

test_pdb failures on Solaris following realpath fixes

Open jaraco opened this issue 1 week ago • 7 comments

@kulikjak reports seeing the following test failure on Solaris following #142371:

======================================================================
ERROR: test_script_target_anonymous_pipe (test.test_pdb.PdbTestCase.test_script_target_anonymous_pipe)
_ScriptTarget doesn't fail on an anonymous pipe.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/builds/cpython-main/Lib/test/test_pdb.py", line 3687, in test_script_target_anonymous_pipe
    code_text = target.code
                ^^^^^^^^^^^
  File "/builds/cpython-main/Lib/pdb.py", line 228, in code
    with io.open_code(self._target) as fp:
         ~~~~~~~~~~~~^^^^^^^^^^^^^^
PermissionError: [Errno 13] Permission denied: '/proc/22733/fd/4'

I am no expert here, but I tried looking into this and apparently opening anything other than regular file or directory from /proc/_pid_/root raises EACCES: https://docs.oracle.com/cd/E88353_01/html/E37852/proc-5.html

It is however possible to open the pipe descriptor via /dev/fd and the following change fixes the issue:

--- ./cpython-main/Lib/test/test_pdb.py
+++ ./cpython-main/Lib/test/test_pdb.py
@@ -3564,8 +3564,9 @@
     def _fd_dir_for_pipe_targets(self):
         """Return a directory exposing live file descriptors, if any."""
         proc_fd = "/proc/self/fd"
-        if os.path.isdir(proc_fd) and os.path.exists(os.path.join(proc_fd, '0')):
-            return proc_fd
+        if not sys.platform.startswith("sunos"):
+            if os.path.isdir(proc_fd) and os.path.exists(os.path.join(proc_fd, '0')):
+                return proc_fd

         dev_fd = "/dev/fd"
         if os.path.isdir(dev_fd) and os.path.exists(os.path.join(dev_fd, '0')):

Originally posted by @kulikjak in https://github.com/python/cpython/issues/142371#issuecomment-3659481440

jaraco avatar Dec 16 '25 15:12 jaraco

Do we know why this issue wasn't picked up by build bots?

jaraco avatar Dec 16 '25 15:12 jaraco

Relevant code is here:

https://github.com/python/cpython/blob/a0434075108efe6acdfba34f42545f4d80ac9a5e/Lib/test/test_pdb.py#L3564-L3580

jaraco avatar Dec 16 '25 15:12 jaraco

Do we know why this issue wasn't picked up by build bots?

I guess because there's no "sunos" buildbot.

jaraco avatar Dec 16 '25 15:12 jaraco

I don't fully understand the motivations behind _fd_dir_for_pipe_targets. I'm not sure when /proc or /dev is relevant. The proposed patch seems reasonable, although I'd like to see it protected by a comment (so it doesn't get optimized away) and probably be in its own stanza (so it's disentangled from the other concerns). Now that these functions are growing more complexity, perhaps they should be rewritten as separate functions so that this function body looks something like:

        return self._fd_dir_from_proc() or self._fd_dir_from_dev()

jaraco avatar Dec 16 '25 16:12 jaraco

Hi, I edited the title. I think this is Solaris-related by the content. SunOS is already deprecated, so I believe the original title was just a typo. Please feel free to change it back if I’m mistaken.

aisk avatar Dec 16 '25 16:12 aisk

Do we know why this issue wasn't picked up by build bots?

I guess because there's no "sunos" buildbot.

Oh! It does fail in the Solaris buildbot (example).

I suspect the failure wasn't reported because that environment isn't at a tier included in reporting.

jaraco avatar Dec 16 '25 16:12 jaraco

The agent encountered an error and was unable to start working on this issue: job builder encountered known error and finalized job: job cannot be created due to repository rules violation: ["Branch creation is blocked due to branch protection rules"].

Copilot avatar Dec 16 '25 16:12 Copilot

As far as I understand, Solaris is not our supported platform anymore. The OS itself is dying too. I don't think we have to do something on this. If there is a quick and clean fix, sure we can apply that, but I don't think it's worth it to spend too much time to investigate the OS specific behavior, or making the code super ugly just to make it work for Solaris.

gaogaotiantian avatar Dec 17 '25 02:12 gaogaotiantian

I'm pleased to say, CoPilot was able to implement fully the fix, including submitting the PR, based on the discussion above.

jaraco avatar Dec 17 '25 07:12 jaraco

Thank you for the fix @jaraco!

Hi, I edited the title. I think this is Solaris-related by the content. SunOS is already deprecated, so I believe the original title was just a typo. Please feel free to change it back if I’m mistaken.

The name is a little confusing due to historical reasons, but what we know as Solaris/Illumos today is reported as sunos5 by the platform module.

Oh! It does fail in the Solaris buildbot (example).

I suspect the failure wasn't reported because that environment isn't at a tier included in reporting.

Indeed. The Solaris buildbot is not being reported, one reason being that it was never green - I am working on that, and thanks to several Python developers, I was able to merge some fixes recently, but it's still not quite there yet...

kulikjak avatar Dec 17 '25 08:12 kulikjak