Skip to content

Commit

Permalink
[3.12] gh-116143: Fix race condition in pydoc _start_server (GH-116144)…
Browse files Browse the repository at this point in the history
… (#116415)

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

Co-authored-by: Itamar Oren <[email protected]>
  • Loading branch information
miss-islington and itamaro authored Mar 6, 2024
1 parent 5c69f60 commit 2528e46
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
7 changes: 4 additions & 3 deletions Lib/pydoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2493,6 +2493,7 @@ def __init__(self, urlhandler, host, port):
threading.Thread.__init__(self)
self.serving = False
self.error = None
self.docserver = None

def run(self):
"""Start the server."""
Expand Down Expand Up @@ -2525,9 +2526,9 @@ def stop(self):

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

Expand Down
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit 2528e46

Please sign in to comment.