-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for alternative
RegistrationFile
(#576)
Closes #563 Joint work with Lionel. This PR implements the alternative `RegistrationFile` approach outlined in JEP 66 that allows for a "handshake" to occur between the client and server on startup. In particular, it allows the server to be in charge of picking the ports, and immediately binds to them as it picks them, avoiding any race conditions here. If the `--connection_file` argument provided to ark can parse into this structure: ```rust pub struct RegistrationFile { /// The transport type to use for ZeroMQ; generally "tcp" pub transport: String, /// The signature scheme to use for messages; generally "hmac-sha256" pub signature_scheme: String, /// The IP address to bind to pub ip: String, /// The HMAC-256 signing key, or an empty string for an unauthenticated /// connection pub key: String, /// ZeroMQ port: Registration messages (handshake) pub registration_port: u16, } ``` Then we assume we are going to be using the handshake method of connecting. Otherwise we parse into the typical `ConnectionFile` structure and assume the Client picked the ports. We expect that the Client _binds_ to a `zmq::REP` socket on `registration_port`. Ark, as the Server, will then _connect_ to this `registration_port` as a `zmq::REQ` socket. Ark will pick ports, bind to them, and send this message over the registration socket: ```rust pub struct HandshakeRequest { /// ZeroMQ port: Control channel (kernel interrupts) pub control_port: u16, /// ZeroMQ port: Shell channel (execution, completion) pub shell_port: u16, /// ZeroMQ port: Standard input channel (prompts) pub stdin_port: u16, /// ZeroMQ port: IOPub channel (broadcasts input/output) pub iopub_port: u16, /// ZeroMQ port: Heartbeat messages (echo) pub hb_port: u16, } ``` Ark will then _immediately_ block, waiting for this `HandshakeReply`: ```rust pub struct HandshakeReply { /// The execution status ("ok" or "error") pub status: Status, } ``` This is just a receipt from the Client that confirms that it received the socket information. If ark does not receive this reply after a few seconds, it will shut itself down. Ark disconnects from the registration socket after receiving the `HandshakeReply`, and the kernel proceeds to start up. --- * Draft registration file * Draft registration handshake * Expose `kernel::read_connection()` and make `kernel::connect()` take connection files again * Ensure ip/transport/signature are always aligned * Even better practice to ensure `endpoint`s are right * Must run `start_kernel()` on a separate thread to be able to perform the handshake * Call `kernel::connect()` from its own thread in amalthea client tests too * Add a `TODO!` about the currently required sleep * Add a `TODO!` about echo tests * Add link to JEP 66 * Downgrade TODO * Remove portpicker dependency * Fix typo in `HandshakeRequest` Co-authored-by: Davis Vaughan <davis@rstudio.com> * Return frontend directly * Comment on timeout --------- Co-authored-by: Lionel Henry <lionel@posit.co> Co-authored-by: Davis Vaughan <davis@posit.co>
- Loading branch information
1 parent
3c8b072
commit 8194c2a
Showing
17 changed files
with
1,018 additions
and
678 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Oops, something went wrong.