regclient / regclient

Docker and OCI Registry Client in Go and tooling using those libraries.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Issue] Race detected when using regclient in tests

peusebiu opened this issue · comments

Current Behavior

Hello, I'm getting a data race on clientResp.backoffUntil when using regclient as library and testing with "-race"
Write is protected by locks, but Read not.

Logs

==================
WARNING: DATA RACE
Write at 0x00c00062c4f0 by goroutine 146:
  github.com/regclient/regclient/internal/reghttp.(*clientResp).backoffSet()
      /home/peusebiu/go/pkg/mod/github.com/regclient/regclient@v0.0.0-20231112134916-05643e5cf2fe/internal/reghttp/http.go:700 +0x3f2
  github.com/regclient/regclient/internal/reghttp.(*clientResp).Next()
      /home/peusebiu/go/pkg/mod/github.com/regclient/regclient@v0.0.0-20231112134916-05643e5cf2fe/internal/reghttp/http.go:540 +0x75a
  github.com/regclient/regclient/internal/reghttp.(*Client).Do()
      /home/peusebiu/go/pkg/mod/github.com/regclient/regclient@v0.0.0-20231112134916-05643e5cf2fe/internal/reghttp/http.go:250 +0x244
  github.com/regclient/regclient/scheme/reg.(*Reg).BlobGet()
      /home/peusebiu/go/pkg/mod/github.com/regclient/regclient@v0.0.0-20231112134916-05643e5cf2fe/scheme/reg/blob.go:62 +0x2b3
  github.com/regclient/regclient.(*RegClient).BlobGet()
      /home/peusebiu/go/pkg/mod/github.com/regclient/regclient@v0.0.0-20231112134916-05643e5cf2fe/blob.go:196 +0x267
  github.com/regclient/regclient.(*RegClient).BlobCopy()
      /home/peusebiu/go/pkg/mod/github.com/regclient/regclient@v0.0.0-20231112134916-05643e5cf2fe/blob.go:122 +0x1564
  github.com/regclient/regclient.(*RegClient).imageCopyBlob()
      /home/peusebiu/go/pkg/mod/github.com/regclient/regclient@v0.0.0-20231112134916-05643e5cf2fe/image.go:893 +0x207
  github.com/regclient/regclient.(*RegClient).imageCopyOpt.func7()
      /home/peusebiu/go/pkg/mod/github.com/regclient/regclient@v0.0.0-20231112134916-05643e5cf2fe/image.go:831 +0x4fa

Previous read at 0x00c00062c4f0 by goroutine 147:
  github.com/regclient/regclient/internal/reghttp.(*clientResp).Next.func1()
      /home/peusebiu/go/pkg/mod/github.com/regclient/regclient@v0.0.0-20231112134916-05643e5cf2fe/internal/reghttp/http.go:354 +0xa4b
  github.com/regclient/regclient/internal/reghttp.(*clientResp).Next()
      /home/peusebiu/go/pkg/mod/github.com/regclient/regclient@v0.0.0-20231112134916-05643e5cf2fe/internal/reghttp/http.go:524 +0x6c4
  github.com/regclient/regclient/internal/reghttp.(*Client).Do()
      /home/peusebiu/go/pkg/mod/github.com/regclient/regclient@v0.0.0-20231112134916-05643e5cf2fe/internal/reghttp/http.go:250 +0x244
  github.com/regclient/regclient/scheme/reg.(*Reg).BlobGet()
      /home/peusebiu/go/pkg/mod/github.com/regclient/regclient@v0.0.0-20231112134916-05643e5cf2fe/scheme/reg/blob.go:62 +0x2b3
  github.com/regclient/regclient.(*RegClient).BlobGet()
      /home/peusebiu/go/pkg/mod/github.com/regclient/regclient@v0.0.0-20231112134916-05643e5cf2fe/blob.go:196 +0x267
  github.com/regclient/regclient.(*RegClient).BlobCopy()
      /home/peusebiu/go/pkg/mod/github.com/regclient/regclient@v0.0.0-20231112134916-05643e5cf2fe/blob.go:122 +0x1564
  github.com/regclient/regclient.(*RegClient).imageCopyBlob()
      /home/peusebiu/go/pkg/mod/github.com/regclient/regclient@v0.0.0-20231112134916-05643e5cf2fe/image.go:893 +0x207
  github.com/regclient/regclient.(*RegClient).imageCopyOpt.func7()
      /home/peusebiu/go/pkg/mod/github.com/regclient/regclient@v0.0.0-20231112134916-05643e5cf2fe/image.go:831 +0x4fa

Goroutine 146 (running) created at:
  github.com/regclient/regclient.(*RegClient).imageCopyOpt()
      /home/peusebiu/go/pkg/mod/github.com/regclient/regclient@v0.0.0-20231112134916-05643e5cf2fe/image.go:825 +0x4c04
  github.com/regclient/regclient.(*RegClient).ImageCopy()
      /home/peusebiu/go/pkg/mod/github.com/regclient/regclient@v0.0.0-20231112134916-05643e5cf2fe/image.go:463 +0x564
  zotregistry.io/zot/pkg/extensions/sync.(*BaseService).syncTag()
      /home/peusebiu/zot/pkg/extensions/sync/service.go:334 +0x16f5
  zotregistry.io/zot/pkg/extensions/sync.(*BaseService).SyncImage()
      /home/peusebiu/zot/pkg/extensions/sync/service.go:211 +0x2e4
  zotregistry.io/zot/pkg/extensions/sync.(*BaseOnDemand).syncImage()
      /home/peusebiu/zot/pkg/extensions/sync/on_demand.go:86 +0x1f8
  zotregistry.io/zot/pkg/extensions/sync.(*BaseOnDemand).SyncImage.func3()
      /home/peusebiu/zot/pkg/extensions/sync/on_demand.go:73 +0xb4

Goroutine 147 (running) created at:
  github.com/regclient/regclient.(*RegClient).imageCopyOpt()
      /home/peusebiu/go/pkg/mod/github.com/regclient/regclient@v0.0.0-20231112134916-05643e5cf2fe/image.go:825 +0x4c04
  github.com/regclient/regclient.(*RegClient).ImageCopy()
      /home/peusebiu/go/pkg/mod/github.com/regclient/regclient@v0.0.0-20231112134916-05643e5cf2fe/image.go:463 +0x564
  zotregistry.io/zot/pkg/extensions/sync.(*BaseService).syncTag()
      /home/peusebiu/zot/pkg/extensions/sync/service.go:334 +0x16f5
  zotregistry.io/zot/pkg/extensions/sync.(*BaseService).SyncImage()
      /home/peusebiu/zot/pkg/extensions/sync/service.go:211 +0x2e4
  zotregistry.io/zot/pkg/extensions/sync.(*BaseOnDemand).syncImage()
      /home/peusebiu/zot/pkg/extensions/sync/on_demand.go:86 +0x1f8
  zotregistry.io/zot/pkg/extensions/sync.(*BaseOnDemand).SyncImage.func3()
      /home/peusebiu/zot/pkg/extensions/sync/on_demand.go:73 +0xb4
==================

Version

github.com/regclient/regclient v0.0.0-20231112134916-05643e5cf2fe

Environment

  • Running as binary or container: library
  • Host platform: linux
  • Registry description: zot

Anything else

Thanks for finding that! I've got a long overdue todo to setup the mocked registry in one place to make more tests possible and improve the coverage. Hopefully I'll get that implemented this month. #599 should fix this one. Let me know if you encounter any others.