From 01059e6ca8fbc132a7e6157c858bd5dbdae62fe7 Mon Sep 17 00:00:00 2001 From: Todd Knight Date: Mon, 17 Aug 2020 10:18:46 -0700 Subject: [PATCH] Wrap StartDbInDocker in a mutex. (#275) * Wrap StartDbInDocker in a mutex. * Adding TODO to debug further. * Clarifying the TODO to point out a race condition. --- internal/db/db.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/internal/db/db.go b/internal/db/db.go index 0d1aec9f34..f1bae9b4fc 100644 --- a/internal/db/db.go +++ b/internal/db/db.go @@ -6,6 +6,7 @@ import ( "fmt" "os" "strings" + "sync" "github.com/golang-migrate/migrate/v4" "github.com/hashicorp/boundary/internal/db/migrations" @@ -80,8 +81,15 @@ func InitDbInDocker(dialect string) (cleanup func() error, retURL, container str return c, url, container, nil } +var ( + mx = sync.Mutex{} +) + // StartDbInDocker func StartDbInDocker(dialect string) (cleanup func() error, retURL, container string, err error) { + // TODO: Debug what part of this method is actually causing race condition issues with our test and fix. + mx.Lock() + defer mx.Unlock() pool, err := dockertest.NewPool("") if err != nil { return func() error { return nil }, "", "", fmt.Errorf("could not connect to docker: %w", err)