mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Shanmugapriyan S <sundar25sengai@gmail.com>
To: mchehab@kernel.org, corbet@lwn.net
Cc: skhan@linuxfoundation.org, rdunlap@infradead.org,
	linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
	Shanmugapriyan S <sundar25sengai@gmail.com>
Subject: [PATCH] jobserver: Handle read errors before claiming a slot
Date: Sat,  7 Nov 2026 05:17:07 +0000	[thread overview]
Message-ID: <20261107051707.1311-1-sundar25sengai@gmail.com> (raw)

If os.read() fails with an error other than EWOULDBLOCK before any
jobserver tokens are collected, the error handler falls through to
self.jobs += slot. Since slot was never assigned, this raises
UnboundLocalError instead of gracefully disabling jobserver parallelism.

Keep returning collected tokens conditional, but reset the claim, warn, and
return for every unexpected read error. Add a regression test that injects
EIO on the first read.

OpenAI Codex assisted with finding the issue and developing the fix and
regression test.

Fixes: b2664a90c171 ("jobserver: Split up the big try: block")
Signed-off-by: Shanmugapriyan S <sundar25sengai@gmail.com>
---
 tools/lib/python/jobserver.py     |  6 ++---
 tools/unittests/test_jobserver.py | 43 +++++++++++++++++++++++++++++++
 2 files changed, 46 insertions(+), 3 deletions(-)
 create mode 100644 tools/unittests/test_jobserver.py

diff --git a/tools/lib/python/jobserver.py b/tools/lib/python/jobserver.py
index 7e94635bf..c8f220a36 100755
--- a/tools/lib/python/jobserver.py
+++ b/tools/lib/python/jobserver.py
@@ -154,9 +154,9 @@ class JobserverExec:
                 #
                 if self.jobs:
                     os.write(self.writer, self.jobs)
-                    self.claim = None
-                    warn('error reading from jobserver pipe', repr(e))
-                    return
+                self.claim = None
+                warn('error reading from jobserver pipe', repr(e))
+                return
             self.jobs += slot
         #
         # Add a bump for our caller's reserveration, since we're just going
diff --git a/tools/unittests/test_jobserver.py b/tools/unittests/test_jobserver.py
new file mode 100644
index 000000000..eafac510c
--- /dev/null
+++ b/tools/unittests/test_jobserver.py
@@ -0,0 +1,43 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: GPL-2.0
+
+"""Unit tests for the GNU make jobserver helper."""
+
+import errno
+import os
+import sys
+import unittest
+
+from unittest.mock import patch
+
+
+SRC_DIR = os.path.dirname(os.path.realpath(__file__))
+sys.path.insert(0, os.path.join(SRC_DIR, "../lib/python"))
+
+from jobserver import JobserverExec
+from unittest_helper import run_unittest
+
+
+class TestJobserverExec(unittest.TestCase):
+    """Test jobserver error handling."""
+
+    @patch.dict(os.environ, {"MAKEFLAGS": "--jobserver-auth=3,4"})
+    @patch("jobserver.warn")
+    @patch("jobserver.os.read", side_effect=OSError(errno.EIO, "I/O error"))
+    @patch("jobserver.os.open", return_value=5)
+    def test_read_error_without_claimed_jobs(self, mock_open, mock_read,
+                                             mock_warn):
+        """A first-read failure disables jobserver use without crashing."""
+        jobserver = JobserverExec()
+
+        jobserver.open()
+
+        self.assertIsNone(jobserver.claim)
+        mock_open.assert_called_once_with("/proc/self/fd/3",
+                                          os.O_RDONLY | os.O_NONBLOCK)
+        mock_read.assert_called_once_with(5, 8)
+        mock_warn.assert_called_once()
+
+
+if __name__ == "__main__":
+    run_unittest(__file__)

base-commit: d48723711bae9b8cdc56719c448ba42fef28cbee
-- 
2.43.0


                 reply	other threads:[~2026-11-07  5:17 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261107051707.1311-1-sundar25sengai@gmail.com \
    --to=sundar25sengai@gmail.com \
    --cc=corbet@lwn.net \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=rdunlap@infradead.org \
    --cc=skhan@linuxfoundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®