-
-
Notifications
You must be signed in to change notification settings - Fork 652
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Port the pantsd nailgun server to rust #9722
Port the pantsd nailgun server to rust #9722
Conversation
3e7ad64
to
48dc7bf
Compare
48dc7bf
to
c69395e
Compare
The commits are useful to review independently, although the last one is a doozy... sorry about that. |
0970711
to
89b159e
Compare
Ok, expecting this to pass CI now. I went a bit further and fully removed the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome. Great work.
class _PantsRunFinishedWithFailureException(Exception): | ||
"""Allows representing a pants run that failed for legitimate reasons (e.g. the target failed to | ||
compile). | ||
def __init__(self, scheduler_service: SchedulerService): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def __init__(self, scheduler_service: SchedulerService): | |
def __init__(self, scheduler_service: SchedulerService) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general we should be trying to add useful type annotations to old code when we modify it.
Will be raised by the exiter passed to LocalPantsRunner. | ||
""" | ||
@staticmethod | ||
def _send_stderr(stderr_fd: int, msg: str): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def _send_stderr(stderr_fd: int, msg: str): | |
def _send_stderr(stderr_fd: int, msg: str) -> None: |
), hermetic_environment_as(**env), argv_as((command,) + args): | ||
# NB: Run implements exception handling, so only the most primitive errors will escape | ||
# this function, where they will be logged to the pantsd.log by the server. | ||
logger.info(f"handling request: `{' '.join(args)}`") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why logger.info
? That will show up by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will only go to pantsd
's log.
src/python/pants/util/contextutil.py
Outdated
termios.tcdrain(dst_fd) | ||
else: | ||
new_dst.flush() | ||
except: # noqa: E722 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
except: # noqa: E722 | |
except BaseException: |
@@ -84,6 +85,17 @@ def hermetic_environment_as(**kwargs: Optional[str]) -> Iterator[None]: | |||
_restore_env(old_environment) | |||
|
|||
|
|||
@contextmanager | |||
def argv_as(args: Tuple[str, ...]) -> Iterator[None]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably have a unit test.
""" | ||
return cast(int, self._native.nailgun_server_await_bound(self._scheduler, nailgun_server)) | ||
|
||
def new_nailgun_server(self, port_requested: int, runner: RawFdRunner) -> Any: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this Any
because it truly could be Any
, or because you don't know the more precise type? If the latter, drop the return type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't know the precise type because it is coming out of CFFI. Will drop.
result = self.lib.nailgun_server_await_bound(scheduler, nailgun_server) | ||
return cast(int, self.context.raise_or_return(result)) | ||
|
||
def new_nailgun_server(self, scheduler, port: int, runner: RawFdRunner) -> Any: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment in scheduler.py
on the Any
return type.
Excited to see a lot of the cruft related to Exiters go away :) |
…restart. # Delete this line to force CI to run Clippy and the Rust tests. [ci skip-rust-tests] # Delete this line to force CI to run the JVM tests. [ci skip-jvm-tests]
[ci skip-jvm-tests]
[ci skip-jvm-tests]
…process (and only called for a signal in pantsd). [ci skip-jvm-tests]
…hook` doesn't need us to actually exit. [ci skip-jvm-tests]
# Delete this line to force CI to run the JVM tests. [ci skip-jvm-tests]
7dde6d3
to
2e3b8fc
Compare
Problem
The setup and teardown of each request made to the nailgun server in
pantsd
had become quite complicated over time... and consequently, slower than it needed to be.Solution
Port
pantsd
's nailgun server to rust using thenails
crate. Additionally, remove theExiter
class, which had accumulated excess responsibilities that can instead be handled by returningExitCode
values. Finally, fix a few broken windows including: double logging to pantsd, double help output, closed file errors on pantsd shutdown, and redundant setup codepaths.Result
There is less code to maintain, and runs of
./pants --enable-pantsd help
take~1.7s
, of which~400ms
are spent in the server. Fixes #9448, fixes #8243, fixes #8206, fixes #8127, fixes #7653, fixes #7613, fixes #7597.