]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.11] gh-116143: Fix race condition in pydoc _start_server (GH-116144) (#116416)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Wed, 6 Mar 2024 15:07:08 +0000 (16:07 +0100)
committerGitHub <noreply@github.com>
Wed, 6 Mar 2024 15:07:08 +0000 (15:07 +0000)
gh-116143: Fix race condition in pydoc _start_server (GH-116144)
(cherry picked from commit 02ee475ee3ce9468d44758df2cd79df9f0926303)

Co-authored-by: Itamar Oren <itamarost@gmail.com>
Lib/pydoc.py
Misc/NEWS.d/next/Library/2024-03-05-20-53-34.gh-issue-116143.sww6Zl.rst [new file with mode: 0644]

index 56a47dc68a66633a52885552375fda3d3db0df25..a8cfeaf925fdce153c1e74947460e0b1f3e58cc0 100755 (executable)
@@ -2491,6 +2491,7 @@ def _start_server(urlhandler, hostname, port):
             threading.Thread.__init__(self)
             self.serving = False
             self.error = None
+            self.docserver = None
 
         def run(self):
             """Start the server."""
@@ -2523,9 +2524,9 @@ def _start_server(urlhandler, hostname, port):
 
     thread = ServerThread(urlhandler, hostname, port)
     thread.start()
-    # Wait until thread.serving is True to make sure we are
-    # really up before returning.
-    while not thread.error and not thread.serving:
+    # Wait until thread.serving is True and thread.docserver is set
+    # to make sure we are really up before returning.
+    while not thread.error and not (thread.serving and thread.docserver):
         time.sleep(.01)
     return thread
 
diff --git a/Misc/NEWS.d/next/Library/2024-03-05-20-53-34.gh-issue-116143.sww6Zl.rst b/Misc/NEWS.d/next/Library/2024-03-05-20-53-34.gh-issue-116143.sww6Zl.rst
new file mode 100644 (file)
index 0000000..07aa312
--- /dev/null
@@ -0,0 +1,3 @@
+Fix a race in pydoc ``_start_server``, eliminating a window in which
+``_start_server`` can return a thread that is "serving" but without a
+``docserver`` set.