Skip to content

Commit c9a83e3

Browse files
authored
Merge pull request moby#50448 from alessio-perugini/fix-data-race-on-list
client: fix datarace when accessing cli.Version field
2 parents 596e088 + a88e13f commit c9a83e3

3 files changed

Lines changed: 28 additions & 0 deletions

File tree

client/container_exec.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,15 @@ func (cli *Client) ContainerExecCreate(ctx context.Context, containerID string,
4646

4747
// ContainerExecStart starts an exec process already created in the docker host.
4848
func (cli *Client) ContainerExecStart(ctx context.Context, execID string, config container.ExecStartOptions) error {
49+
// Make sure we negotiated (if the client is configured to do so),
50+
// as code below contains API-version specific handling of options.
51+
//
52+
// Normally, version-negotiation (if enabled) would not happen until
53+
// the API request is made.
54+
if err := cli.checkVersion(ctx); err != nil {
55+
return err
56+
}
57+
4958
if versions.LessThan(cli.ClientVersion(), "1.42") {
5059
config.ConsoleSize = nil
5160
}

client/container_list.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ func (cli *Client) ContainerList(ctx context.Context, options container.ListOpti
3535
}
3636

3737
if options.Filters.Len() > 0 {
38+
// Make sure we negotiated (if the client is configured to do so),
39+
// as code below contains API-version specific handling of options.
40+
//
41+
// Normally, version-negotiation (if enabled) would not happen until
42+
// the API request is made.
43+
if err := cli.checkVersion(ctx); err != nil {
44+
return nil, err
45+
}
46+
3847
//nolint:staticcheck // ignore SA1019 for old code
3948
filterJSON, err := filters.ToParamWithVersion(cli.version, options.Filters)
4049
if err != nil {

client/events.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ func (cli *Client) Events(ctx context.Context, options events.ListOptions) (<-ch
2323
go func() {
2424
defer close(errs)
2525

26+
// Make sure we negotiated (if the client is configured to do so),
27+
// as code below contains API-version specific handling of options.
28+
//
29+
// Normally, version-negotiation (if enabled) would not happen until
30+
// the API request is made.
31+
if err := cli.checkVersion(ctx); err != nil {
32+
close(started)
33+
errs <- err
34+
return
35+
}
2636
query, err := buildEventsQueryParams(cli.version, options)
2737
if err != nil {
2838
close(started)

0 commit comments

Comments
 (0)