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

Reaper doesn't appear to be thread safe #192

Closed
nwv-danvulpe opened this issue May 12, 2020 · 1 comment · Fixed by #198
Closed

Reaper doesn't appear to be thread safe #192

nwv-danvulpe opened this issue May 12, 2020 · 1 comment · Fixed by #198

Comments

@nwv-danvulpe
Copy link

nwv-danvulpe commented May 12, 2020

Describe the bug
Having recently upgraded from 0.4.0 to 0.5.1 I noticed some tests started failing with:

could not start container: failed to create container: connecting to reaper failed: Connecting to Ryuk on  failed: dial tcp: missing address

We run a number of tests in parallel (in the same package) spinning up a few containers (less than 5). If we remove t.Parallel() the test pass successfully, but they take longer to complete.

To Reproduce
Can you write a unit test to reproduce your issue?


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

func TestParallelContainers(t *testing.T) {
	ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
	t.Cleanup(cancel)

	for i := 0; i < 3; i++ {
		t.Run(fmt.Sprintf("iteration_%d", i), func(t *testing.T) {
			t.Parallel()
			createTestContainer(t, ctx)
		})
	}
}

func createTestContainer(t *testing.T, ctx context.Context) int {
	req := testcontainers.ContainerRequest{
		Image:        "localstack/localstack:latest",
		ExposedPorts: []string{"4584/tcp", "8080/tcp"},
		Env: map[string]string{
			"SERVICES": "secretsmanager",
		},
		WaitingFor: wait.ForListeningPort("4584/tcp"),
		//SkipReaper: true,
	}
	container, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
		ContainerRequest: req,
		Started:          true,
	})
	if err != nil {
		t.Fatalf("could not start container: %v", err)
	}
	port, err := container.MappedPort(ctx, "4584")
	if err != nil {
		t.Fatalf("could not get mapped port: %v", err)
	}

	t.Cleanup(func() {
		container.Terminate(context.Background())
	})

	return port.Int()
}

Expected behavior
It should be possible to start containers in parallel.

Additional context
Test output:

=== RUN   TestParallelContainers
--- FAIL: TestParallelContainers (0.00s)
=== RUN   TestParallelContainers/iteration_0
=== PAUSE TestParallelContainers/iteration_0
=== CONT  TestParallelContainers/iteration_0
    --- FAIL: TestParallelContainers/iteration_0 (0.01s)
=== RUN   TestParallelContainers/iteration_1
=== PAUSE TestParallelContainers/iteration_1
=== CONT  TestParallelContainers/iteration_1
    TestParallelContainers/iteration_1: demo_test.go:39: could not start container: failed to create container: connecting to reaper failed: Connecting to Ryuk on  failed: dial tcp: missing address
    TestParallelContainers/iteration_0: demo_test.go:39: could not start container: failed to create container: connecting to reaper failed: Connecting to Ryuk on  failed: dial tcp: missing address
2020/05/12 09:57:27 Starting container id: 87b3a8c0ba74 image: quay.io/testcontainers/ryuk:0.2.3
2020/05/12 09:57:28 Waiting for container id 87b3a8c0ba74 image: quay.io/testcontainers/ryuk:0.2.3
2020/05/12 09:57:28 Container is ready id: 87b3a8c0ba74 image: quay.io/testcontainers/ryuk:0.2.3
2020/05/12 09:57:28 Starting container id: c3bf40970170 image: localstack/localstack:latest
2020/05/12 09:57:28 Waiting for container id c3bf40970170 image: localstack/localstack:latest
2020/05/12 09:57:43 Container is ready id: c3bf40970170 image: localstack/localstack:latest
    --- FAIL: TestParallelContainers/iteration_1 (0.01s)
=== RUN   TestParallelContainers/iteration_2
=== PAUSE TestParallelContainers/iteration_2
=== CONT  TestParallelContainers/iteration_2
    --- PASS: TestParallelContainers/iteration_2 (16.15s)
FAIL

Process finished with exit code 1
@gianarb
Copy link
Member

gianarb commented May 13, 2020

I think something broke when working at #174 .
I will have a look at thanks a lot for writing such a nice reproducible gem!

gianarb added a commit that referenced this issue May 24, 2020
fixes #192 - guard access to reaper with a mutex
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants