Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Force sequential runs under pantsd (#7781)
## Problem It's not currently safe to have multiple parallel pants runs with the daemon enabled. However, this was not enforced (context: #7751). ## Solution - Implement a lock in `PailgunServer`, so that each request thread waits to acquire it (in `PailgunServer.process_request_thread`). - Implement an option that is passed via the environment, to each request, to communicate how long should a request wait for the lock before timing out. ## Result In the cases where a single pants run is running at a time, the UX is unchanged. When a request is run, we have three cases: - If we specify a positive timeout (or if we leave it by default), and the request finishes before we time out, the request waits for a bit and then runs: ``` $ ./pants --enable-pantsd --pantsd-run-start-timeout=20 list src/scala:: Another pants run was found, starting waiting for up to 20.0s for it to finish Waiting for request to finish (1.0s total)... Waiting for request to finish (2.0s total)... Waiting for request to finish (3.0s total)... Waiting for request to finish (4.0s total)... Waiting for request to finish (5.0s total)... Waiting for request to finish (6.0s total)... Waiting for request to finish (7.0s total)... Waiting for request to finish (8.0s total)... Waiting for request to finish (9.0s total)... src/scala/org/pantsbuild/zinc/cache:cache src/scala/org/pantsbuild/zinc/analysis:analysis src/scala/org/pantsbuild/zinc/options:options src/scala/org/pantsbuild/zinc/compiler:compiler src/scala/org/pantsbuild/zinc/extractor:extractor src/scala/org/pantsbuild/zinc/scalautil:scalautil src/scala/org/pantsbuild/zinc/bootstrapper:bootstrapper src/scala/org/pantsbuild/zinc/util:util ``` - If we specify a timeout and hit it, the run will fail with a useful error: ``` $ ./pants --enable-pantsd --pantsd-run-start-timeout="0" list :: Another pants run was found, starting waiting for up to 0.0s for it to finish Traceback (most recent call last): File "/Users/bescobar/workspace/otherpants/src/python/pants/pantsd/pailgun_server.py", line 259, in process_request_thread with self.ensure_request_is_exclusive(environment, request): File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/contextlib.py", line 112, in __enter__ return next(self.gen) File "/Users/bescobar/workspace/otherpants/src/python/pants/pantsd/pailgun_server.py", line 246, in ensure_request_is_exclusive raise ExclusiveRequestTimeout("Timed out while waiting for another pants run to finish") pants.pantsd.pailgun_server.ExclusiveRequestTimeout: Timed out while waiting for another pants run to finish ``` - If we specify a **negative** timeout, the request will block _potentially_ forever: ``` $ ./pants --enable-pantsd --pantsd-run-start-timeout=-1 list src/scala:: Another pants run was found, starting waiting forever for it to finish Waiting for request to finish (1.0s total)... Waiting for request to finish (2.0s total)... Waiting for request to finish (3.0s total)... Waiting for request to finish (4.0s total)... Waiting for request to finish (5.0s total)... Waiting for request to finish (6.0s total)... Waiting for request to finish (7.0s total)... Waiting for request to finish (8.0s total)... Waiting for request to finish (9.0s total)... Waiting for request to finish (10.0s total)... Waiting for request to finish (11.0s total)... src/scala/org/pantsbuild/zinc/extractor:extractor src/scala/org/pantsbuild/zinc/compiler:compiler src/scala/org/pantsbuild/zinc/analysis:analysis src/scala/org/pantsbuild/zinc/bootstrapper:bootstrapper src/scala/org/pantsbuild/zinc/options:options src/scala/org/pantsbuild/zinc/util:util src/scala/org/pantsbuild/zinc/scalautil:scalautil src/scala/org/pantsbuild/zinc/cache:cache ``` **All of the new output is to stderr** Fixes #7751. Commits should _mostly_ make sense independently.
- Loading branch information
Showing
5 changed files
with
236 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters