[3.11] gh-116143: Fix race condition in pydoc _start_server (GH-116144) (#116416)

gh-116143: Fix race condition in pydoc _start_server (GH-116144)
(cherry picked from commit 02ee475ee3)

Co-authored-by: Itamar Oren <itamarost@gmail.com>
This commit is contained in:
Miss Islington (bot) 2024-03-06 16:07:08 +01:00 committed by GitHub
parent d69bef6080
commit 26f7956f8f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 3 deletions

View file

@ -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

View file

@ -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.