The new agent API calls for ATTACH_CONTAINER_INPUT and ATTACH_CONTAINER_OUTPUT are intimately intertwined. That is, most attach operations will likely want to call both ATTACH_CONTAINER_INPUT and ATTACH_CONTAINER_OUTPUT in order to attach all three of stdin, stdout and stderr to a local terminal.
Moreover, we plan to allow multiple ATTACH_CONTAINER_OUTPUT calls can be made for the same container (i.e. from multiple clients), while only one ATTACH_CONTAINER_INPUT call will be allowed to connect at a time.
In order to ensure that these calls are properly grouped (as well as to ensure that any state they need to share is properly confined), we will lazily launch a “per-container” actor to manage all ATTACH_CONTAINER_OUTPUT and ATTACH_CONTAINER_INPUT calls on behalf of a container.
It will be the responsibility of this actor to:
- Manage the read end of the pipe set up by the HTTP handler for the ATTACH_CONTAINER_INPUT call for a given container.
- Manage the write end of the pipes set up by the HTTP handler for all ATTACH_CONTAINER_OUTPUT calls for a given container.
- Establish a connection to a per-container “I/O switchboard” (discussed below) in order to forward data coming from the ATTACH_CONTAINER_INPUT pipe to the switchboard.
- Establish a second connection to the per-container “I/O switchboard” to stream all stdout data coming from the switchboard to all ATTACH_CONTAINER_OUTPUT pipes.
- Establish a third connection to the per-container “I/O switchboard” to stream all stderr data coming from the switchboard to all ATTACH_CONTAINER_OUTPUT pipes.