Skip to content

bug: go test -race reports a data race in backend build test #533

@aftersnow

Description

@aftersnow

Problem

go test -race currently reports a data race in pkg/backend/build on main.

Reproduced on 1d480ded52ab1bda1aea3d03a452ed901325344d with:

GOCACHE=$(mktemp -d /tmp/modctl-current-gocache-race.XXXXXX) go test -race ./pkg/backend ./pkg/backend/build

The pkg/backend package passed in that run, but pkg/backend/build failed with a race in TestBuilderSuite/TestBuildLayer/successful_build_layer.

Race summary:

WARNING: DATA RACE
Write:
  io.(*pipe).write
  archive/tar.(*Writer).WriteHeader
  github.com/modelpack/modctl/pkg/archiver.Tar.func1
      pkg/archiver/archiver.go:114

Previous read:
  fmt.Sprintf
  github.com/stretchr/testify/mock.Arguments.Diff
  github.com/modelpack/modctl/test/mocks/backend/build.(*OutputStrategy).OutputLayer
  github.com/modelpack/modctl/pkg/backend/build.(*abstractBuilder).BuildLayer
      pkg/backend/build/builder.go:191
  github.com/modelpack/modctl/pkg/backend/build.(*BuilderTestSuite).TestBuildLayer.func1
      pkg/backend/build/builder_test.go:129

Why it matters

The test passes without -race, so regular CI does not catch it. The current mock expectation passes a live *io.PipeReader into testify matching/diff logic while the tar writer goroutine is still writing to the paired pipe. The race detector catches concurrent access during test execution.

Expected behavior

go test -race ./pkg/backend/build should pass cleanly, or the test should avoid passing a live pipe object into mock diff/matching while another goroutine is mutating the pipe state.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions