From f4b9679abd629fdae91992dca6a5bba7447c6dea Mon Sep 17 00:00:00 2001 From: zc Date: Mon, 14 Feb 2022 00:50:29 +0800 Subject: [PATCH] copy opts.LogConfig to avoid concurrent modification (#550) --- engine/docker/container.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/engine/docker/container.go b/engine/docker/container.go index 346b018be..c3104ee20 100644 --- a/engine/docker/container.go +++ b/engine/docker/container.go @@ -117,17 +117,19 @@ func (e *Engine) VirtualizationCreate(ctx context.Context, opts *enginetypes.Vir if networkMode == "" { networkMode = dockercontainer.NetworkMode(e.config.Docker.NetworkMode) } - // log config - if opts.LogConfig == nil { - opts.LogConfig = map[string]string{} + // log config, copy to avoid concurrent writes + logConfig := map[string]string{} + for k, v := range opts.LogConfig { + logConfig[k] = v } - opts.LogConfig["mode"] = "non-blocking" - opts.LogConfig["max-buffer-size"] = "4m" - opts.LogConfig["tag"] = fmt.Sprintf("%s {{.ID}}", opts.Name) + + logConfig["mode"] = "non-blocking" + logConfig["max-buffer-size"] = "4m" + logConfig["tag"] = fmt.Sprintf("%s {{.ID}}", opts.Name) if opts.Debug { opts.LogType = e.config.Docker.Log.Type for k, v := range e.config.Docker.Log.Config { - opts.LogConfig[k] = v + logConfig[k] = v } } // add node IP @@ -205,7 +207,7 @@ func (e *Engine) VirtualizationCreate(ctx context.Context, opts *enginetypes.Vir DNS: opts.DNS, LogConfig: dockercontainer.LogConfig{ Type: opts.LogType, - Config: opts.LogConfig, + Config: logConfig, }, NetworkMode: networkMode, RestartPolicy: dockercontainer.RestartPolicy{