Skip to content

Data Race in meilisearch.New() #618

Open
@zeisss

Description

@zeisss

Description
In our tests we initialize multiple meilisearch clients concurrently. Running our go tests with -count 5 -race predicatably returns a data race error for meilisearch.New() as it concurrently modifies the default options:

defOpt := defaultMeiliOpt
for _, opt := range options {
opt(defOpt)
}

Expected behavior
meilisearch.New() should be callable concurrently by multiple goroutines in tests.

I think the easiest fix is to copy the defaultOptions instead of using a reference.

Current behavior

WARNING: DATA RACE
Write at 0x000104aeac48 by goroutine 58:
  github.com/gramLabs/stormforge-cloud/pkg/testutil.WithMeilisearch.WithAPIKey.func4()
      /Users/zeisss/go/pkg/mod/github.com/meilisearch/[email protected]/options.go:65 +0x40
  github.com/meilisearch/meilisearch-go.New()
      /Users/zeisss/go/pkg/mod/github.com/meilisearch/[email protected]/meilisearch.go:22 +0x78
  github.com/redacted/my-project/pkg/testutil.WithMeilisearch()
      /Users/zeisss/p/redacted/my-project/pkg/testutil/meilisearch.go:60 +0x54c

Environment (please complete the following information):

  • OS: Mac
  • meilisearch-go version: v0.31.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions