8000 deprecate pkg/stdcopy, move to api/stdcopy by thaJeztah · Pull Request #50462 · moby/moby · GitHub
[go: up one dir, main page]

Skip to content

Conversation

thaJeztah
Copy link
Member
@thaJeztah thaJeztah commented Jul 21, 2025

The stdcopy package is used to produce and read multiplexed streams for "attach" and "logs". It is used both by the API server (to produce), and the client (to read / de-multiplex).

Move it to the api package, so that it can be included in the api module.

- Human readable description for the release notes

Go-SDK: deprecate `pkg/stdcopy`, which was moved to `api/stdcopy`.

- A picture of a cute animal (not mandatory but encouraged)

@thaJeztah thaJeztah added this to the 29.0.0 milestone Jul 21, 2025
@thaJeztah thaJeztah added status/2-code-review impact/deprecation area/go-sdk impact/go-sdk Noteworthy (compatibility changes) in the Go SDK release-blocker PRs we want to block a release on labels Jul 21, 2025
import (
"io"

"github.com/docker/docker/api/stdcopy"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was on the fence on the best location for this; it's not a "type" (really?), so it didn't feel right to put it under types/. Also considered if we needed a utils/ or common/ package underneath api/.

☝️ input welcome!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe api/internal/stdcopy, or api/pkg/stdcopy if internalization is too strict

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tricky bit is that it's used by the client; it's the implementation to decode these multiplexed streams, so it can't be internal.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's basically the implementation to both produce and handle this format;

moby/api/swagger.yaml

Lines 8657 to 8700 in a1ee566

### Stream format
When the TTY setting is disabled in [`POST /containers/create`](#operation/ContainerCreate),
the HTTP Content-Type header is set to application/vnd.docker.multiplexed-stream
and the stream over the hijacked connected is multiplexed to separate out
`stdout` and `stderr`. The stream consists of a series of frames, each
containing a header and a payload.
The header contains the information which the stream writes (`stdout` or
`stderr`). It also contains the size of the associated frame encoded in
the last four bytes (`uint32`).
It is encoded on the first eight bytes like this:
```go
header := [8]byte{STREAM_TYPE, 0, 0, 0, SIZE1, SIZE2, SIZE3, SIZE4}
```
`STREAM_TYPE` can be:
- 0: `stdin` (is written on `stdout`)
- 1: `stdout`
- 2: `stderr`
`SIZE1, SIZE2, SIZE3, SIZE4` are the four bytes of the `uint32` size
encoded as big endian.
Following the header is the payload, which is the specified number of
bytes of `STREAM_TYPE`.
The simplest way to implement this protocol is the following:
1. Read 8 bytes.
2. Choose `stdout` or `stderr` depending on the first byte.
3. Extract the frame size from the last four bytes.
4. Read the extracted size and output it on the correct output.
5. Goto 1.
### Stream format when using a TTY
When the TTY setting is enabled in [`POST /containers/create`](#operation/ContainerCreate),
the stream is not multiplexed. The data exchanged over the hijacked
connection is simply the raw data from the process PTY and client's
`stdin`.

@thaJeztah
Copy link
Member Author

Derp; need to adjust the validation;

These files import internal code: (either directly or indirectly)
 - pkg/stdcopy/stdcopy_deprecated.go imports github.com/docker/docker/api/stdcopy

@thaJeztah thaJeztah requested a review from dmcgowan July 21, 2025 17:03
The stdcopy package is used to produce and read multiplexed streams for
"attach" and "logs". It is used both by the AP
5CC0
I server (to produce), and
the client (to read / de-multiplex).

Move it to the api package, so that it can be included in the api module.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/go-sdk impact/deprecation impact/go-sdk Noteworthy (compatibility changes) in the Go SDK release-blocker PRs we want to block a release on status/2-code-review
Projects
Development

Successfully merging this pull request may close these issues.

4 participants
0