Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion mypy/dmypy_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ def __init__(self, options: Options,

def serve(self) -> None:
"""Serve requests, synchronously (no thread or fork)."""
command = None
try:
sock = self.create_listening_socket()
if self.timeout is not None:
Expand Down Expand Up @@ -200,7 +201,13 @@ def serve(self) -> None:
reset_global_state()
sys.exit(0)
finally:
os.unlink(STATUS_FILE)
# If the final command is something other than a clean
# stop, remove the status file. (We can't just
# simplify the logic and always remove the file, since
# that could cause us to remove a future server's
# status file.)
if command != 'stop':
os.unlink(STATUS_FILE)
finally:
shutil.rmtree(self.sock_directory)
exc_info = sys.exc_info()
Expand Down Expand Up @@ -235,6 +242,11 @@ def cmd_status(self) -> Dict[str, object]:

def cmd_stop(self) -> Dict[str, object]:
"""Stop daemon."""
# We need to remove the status file *before* we complete the
# RPC. Otherwise a race condition exists where a subsequent
# command can see a status file from a dying server and think
# it is a live one.
os.unlink(STATUS_FILE)
return {}

def cmd_run(self, version: str, args: Sequence[str]) -> Dict[str, object]:
Expand Down