]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-116143: Fix race condition in pydoc _start_server (#116144)
authorItamar Oren <itamarost@gmail.com>
Wed, 6 Mar 2024 14:39:51 +0000 (06:39 -0800)
committerGitHub <noreply@github.com>
Wed, 6 Mar 2024 14:39:51 +0000 (07:39 -0700)
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 407c0205c7ab66560d4cbfe14c1839160e18b5a5..08fd7aba7c9472228312cf8fad30e0f680e94051 100755 (executable)
@@ -2504,6 +2504,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."""
@@ -2536,9 +2537,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.