Skip to content

[Bug]: Restart Container with Log Consumer is not working #2572

@hahahannes

Description

@hahahannes

Testcontainers version

0.31.0

Using the latest Testcontainers version?

Yes

Host OS

Linux Ubuntu 22.04

Host arch

x86

Go version

1.22

Docker version

Client: Docker Engine - Community
 Version:           20.10.18
 API version:       1.41
 Go version:        go1.18.6
 Git commit:        b40c2f6
 Built:             Thu Sep  8 23:11:43 2022
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.18
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.18.6
  Git commit:       e42327a
  Built:            Thu Sep  8 23:09:30 2022
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.8
  GitCommit:        9cd3357b7fd7218e4aec3eae239db1f68a5a6ec6
 runc:
  Version:          1.1.4
  GitCommit:        v1.1.4-0-g5fd4c4d
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

Docker info

Client:
 Context:    default
 Debug Mode: false
 Plugins:
  app: Docker App (Docker Inc., v0.9.1-beta3)
  buildx: Docker Buildx (Docker Inc., v0.9.1-docker)
  compose: Docker Compose (Docker Inc., v2.12.2)
  scan: Docker Scan (Docker Inc., v0.17.0)

Server:
 Containers: 21
  Running: 21
  Paused: 0
  Stopped: 0
 Images: 750
 Server Version: 20.10.18
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: systemd
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux nvidia runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 9cd3357b7fd7218e4aec3eae239db1f68a5a6ec6
 runc version: v1.1.4-0-g5fd4c4d
 init version: de40ad0
 Security Options:
  apparmor
  seccomp
   Profile: default
  cgroupns
 Kernel Version: 5.19.0-76051900-generic
 Operating System: Pop!_OS 22.04 LTS
 OSType: linux
 Architecture: x86_64
 CPUs: 20
 Total Memory: 62.48GiB
 Name: pop-os
 ID: P6NI:BJKY:SNIH:SXGM:VHDO:AI5W:56BU:OSUH:43E4:EG72:Z3IM:ISTY
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false
 Default Address Pools:
   Base: 172.22.0.1/16, Size: 24

What happened?

Restarting a container with a log consumer results in a error after the second start command.
In the following example, I restart a simple hello world container with a custom log consumer.
I expected that the log consumer wont cause an error.

package main

import (
	"context"
	"time"
	"fmt"
	"github.com/testcontainers/testcontainers-go"
)


type LogConsumer struct {
	LogChannel chan string
}

func (c LogConsumer) Accept(rawLog testcontainers.Log) {
	log := string(rawLog.Content)
	c.LogChannel <- log
}

func NewLogConsumer() *LogConsumer {
	return &LogConsumer{
		LogChannel: make(chan string),
	}
}

func main() {
	logConsumer := NewLogConsumer()

	ctx := context.Background()
	container, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
		ContainerRequest: testcontainers.ContainerRequest{
			Image:           "hello-world",
			AlwaysPullImage: true,
			LogConsumerCfg: &testcontainers.LogConsumerConfig{
				Consumers: []testcontainers.LogConsumer{logConsumer},
			},
		},
		Started: false,
	})

	err = container.Start(ctx)
	if err != nil {
		fmt.Println(err)
	}
	d := 30*time.Second
	err = container.Stop(ctx, &d)
	if err != nil {
		fmt.Println(err)
	}
	err = container.Start(ctx)
	if err != nil {
		fmt.Println("Cant start container: " + err.Error())
	}
}

Relevant log output

[...]
For more examples and ideas, visit:
 https://docs.docker.com/get-started/


Cant start container: log production already started


### Additional information

_No response_

Metadata

Metadata

Assignees

Labels

bugAn issue with the library

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions