Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Random characters in the output of io.Reader returned in Exec(ctx context.Context, cmd []string) #620

Closed
cyberbeast opened this issue Nov 14, 2022 · 4 comments · Fixed by #624
Labels
bug An issue with the library

Comments

@cyberbeast
Copy link

Testcontainers version

0.15.0

Using the latest Testcontainers version?

Yes

Host OS

Macos

Host arch

x86

Go version

1.19

Docker version

Client:
 Cloud integration: v1.0.29
 Version:           20.10.20
 API version:       1.41
 Go version:        go1.18.7
 Git commit:        9fdeb9c
 Built:             Tue Oct 18 18:20:35 2022
 OS/Arch:           darwin/amd64
 Context:           default
 Experimental:      true

Server: Docker Desktop 4.13.1 (90346)
 Engine:
  Version:          20.10.20
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.18.7
  Git commit:       03df974
  Built:            Tue Oct 18 18:18:35 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:
  buildx: Docker Buildx (Docker Inc., v0.9.1)
  compose: Docker Compose (Docker Inc., v2.12.1)
  dev: Docker Dev Environments (Docker Inc., v0.0.3)
  extension: Manages Docker extensions (Docker Inc., v0.2.13)
  sbom: View the packaged-based Software Bill Of Materials (SBOM) for an image (Anchore Inc., 0.6.0)
  scan: Docker Scan (Docker Inc., v0.21.0)

Server:
 Containers: 0
  Running: 0
  Paused: 0
  Stopped: 0
 Images: 12
 Server Version: 20.10.20
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 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 runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 9cd3357b7fd7218e4aec3eae239db1f68a5a6ec6
 runc version: v1.1.4-0-g5fd4c4d
 init version: de40ad0
 Security Options:
  seccomp
   Profile: default
  cgroupns
 Kernel Version: 5.15.49-linuxkit
 Operating System: Docker Desktop
 OSType: linux
 Architecture: x86_64
 CPUs: 8
 Total Memory: 7.772GiB
 Name: docker-desktop
 ID: XS7M:CTCG:HOAE:PMYH:5IOL:TEXS:CYEV:UCQ6:UISC:4IIN:2U6L:XJ2I
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 HTTP Proxy: http.docker.internal:3128
 HTTPS Proxy: http.docker.internal:3128
 No Proxy: hubproxy.docker.internal
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  hubproxy.docker.internal:5000
  127.0.0.0/8
 Live Restore Enabled: false

What happened?

The io.Reader returned by Exec() contains random characters. For my setup I am running a rabbitmq:management container and I am running rabbitmqctl command to list some connection information, like so,

...
request := tc.GenericContainerRequest{
		ContainerRequest: tc.ContainerRequest{
			Image:        c.image,
			ExposedPorts: []string{"5672/tcp", "15672/tcp"},
			WaitingFor:   wait.ForLog("Server startup complete").WithStartupTimeout(c.timeout),
			AutoRemove: true,
		},
		Started: true,
	}

	container, err := tc.GenericContainer(ctx, request)
	if err != nil {
		return nil, fmt.Errorf("failed to start container: %v", err)
	}
...
_, reader, err := c.Exec(ctx, []string{"rabbitmqctl", "list_connections", "name", "state", "--formatter", "json"})
if err != nil {
return err
}

The output in the returned reader seems to contain random characters as such,

[
�{"name":"172.17.0.1:64168 -> 172.17.0.3:5672","state":"running"}
,{"name":"172.17.0.1:64184 -> 172.17.0.3:5672","state":"running"}
]

To rule out a formatter error on rabbitmqctl, I tried running the command with a csv formatter, and I see the same behavior with random characters in the output of the reader. (Again there are no random characters when the same command is run in the docker container after execing into it via docker exec -it <container_id> bash

_, reader, err := c.Exec(ctx, []string{"rabbitmqctl", "list_connections", "name", "state", "--formatter", "csv"})
if err != nil {
return err
}
o"name","state"
"172.17.0.1:55048 -> 172.17.0.3:5672","running"
"172.17.0.1:55060 -> 172.17.0.3:5672","running"

The output looks clean when executed outside of testcontainers-go inside the container directly. I see in the source code that the tests for Exec don't seem to cover the reader returned from the Exec method.

Any ideas why this is happening?

Relevant log output

No response

Additional information

No response

@cyberbeast cyberbeast added the bug An issue with the library label Nov 14, 2022
@cyberbeast cyberbeast changed the title [Bug]: [Bug]: Random characters in the output of io.Reader returned in Exec(ctx context.Context, cmd []string) Nov 14, 2022
@mdelapenya
Copy link
Collaborator

Hi @cyberbeast I'm able to reproduce it and would start working on a fix, unless you would like to do it yourself. Thoughts?

@mdelapenya
Copy link
Collaborator

@cyberbeast I prioritised this bug and submitted a fix in #624. I'd appreciate your review

@cyberbeast
Copy link
Author

Thank you for the fix. I'll review.

@kuisathaverat
Copy link
Contributor

For future me, the issue is resolved by adding a multiplexer parameter to the exec call.

import (
...
tcexec "github.com/testcontainers/testcontainers-go/exec"
...
)

...
_, result, err := vaultContainer.Exec(ctx, cmds, tcexec.Multiplexed())
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An issue with the library
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants