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

DATA RACE for LocalFile.index #367

Open
informalict opened this issue Jan 24, 2025 · 4 comments
Open

DATA RACE for LocalFile.index #367

informalict opened this issue Jan 24, 2025 · 4 comments
Labels
bug Something isn't working

Comments

@informalict
Copy link

version: v0.20.0

There is a DATA RACE for index field in LocalFile struct in file the index/rolodex_file_loader.go.

line 194:

l.index = index

and line 231

if l.index != nil && l.index.root == nil {

So reading from index (line 231) can happen at the same time as writing to it (line 194).

Details:

WARNING: DATA RACE
Read at 0x00c000316300 by goroutine 638:
  github.com/pb33f/libopenapi/index.(*LocalFile).GetContentAsYAMLNode()
      /home/runner/go/pkg/mod/github.com/pb33f/[email protected]/index/rolodex_file_loader.go:231 +0x444
  github.com/pb33f/libopenapi/index.(*rolodexFile).GetContentAsYAMLNode()
      /home/runner/go/pkg/mod/github.com/pb33f/[email protected]/index/rolodex_file.go:79 +0xd2
  github.com/pb33f/libopenapi/index.(*SpecIndex).lookupRolodex()
      /home/runner/go/pkg/mod/github.com/pb33f/[email protected]/index/find_component.go:151 +0x1be
  github.com/pb33f/libopenapi/index.(*SpecIndex).FindComponent()
      /home/runner/go/pkg/mod/github.com/pb33f/[email protected]/index/find_component.go:31 +0x147
  github.com/pb33f/libopenapi/index.(*SpecIndex).ExtractComponentsFromRefs.func1()
      /home/runner/go/pkg/mod/github.com/pb33f/[email protected]/index/extract_refs.go:657 +0x5f1
  github.com/pb33f/libopenapi/index.(*SpecIndex).ExtractComponentsFromRefs()
      /home/runner/go/pkg/mod/github.com/pb33f/[email protected]/index/extract_refs.go:721 +0x319
  github.com/pb33f/libopenapi/index.createNewIndex()
      /home/runner/go/pkg/mod/github.com/pb33f/[email protected]/index/spec_index.go:96 +0x584
  github.com/pb33f/libopenapi/index.NewSpecIndexWithConfig()
      /home/runner/go/pkg/mod/github.com/pb33f/[email protected]/index/spec_index.go:56 +0x71a
  github.com/pb33f/libopenapi/index.(*LocalFile).Index()
      /home/runner/go/pkg/mod/github.com/pb33f/[email protected]/index/rolodex_file_loader.go:191 +0x118
  github.com/pb33f/libopenapi/index.(*Rolodex).IndexTheRolodex.func1.1()
      /home/runner/go/pkg/mod/github.com/pb33f/[email protected]/index/rolodex.go:253 +0x1f2
  github.com/pb33f/libopenapi/index.(*Rolodex).IndexTheRolodex.func1.gowrap1()
      /home/runner/go/pkg/mod/github.com/pb33f/[email protected]/index/rolodex.go:278 +0x6e

Previous write at 0x00c000316300 by goroutine 639:
  github.com/pb33f/libopenapi/index.(*LocalFile).Index()
      /home/runner/go/pkg/mod/github.com/pb33f/[email protected]/index/rolodex_file_loader.go:194 +0x190
  github.com/pb33f/libopenapi/index.(*Rolodex).IndexTheRolodex.func1.1()
      /home/runner/go/pkg/mod/github.com/pb33f/[email protected]/index/rolodex.go:253 +0x1f2
  github.com/pb33f/libopenapi/index.(*Rolodex).IndexTheRolodex.func1.gowrap1()
      /home/runner/go/pkg/mod/github.com/pb33f/[email protected]/index/rolodex.go:278 +0x6e

Goroutine 638 (running) created at:
  github.com/pb33f/libopenapi/index.(*Rolodex).IndexTheRolodex.func1()
      /home/runner/go/pkg/mod/github.com/pb33f/[email protected]/index/rolodex.go:278 +0x489
  github.com/pb33f/libopenapi/index.(*Rolodex).IndexTheRolodex.gowrap1()
      /home/runner/go/pkg/mod/github.com/pb33f/[email protected]/index/rolodex.go:301 +0xa4

Goroutine 639 (finished) created at:
  github.com/pb33f/libopenapi/index.(*Rolodex).IndexTheRolodex.func1()
      /home/runner/go/pkg/mod/github.com/pb33f/[email protected]/index/rolodex.go:278 +0x489
  github.com/pb33f/libopenapi/index.(*Rolodex).IndexTheRolodex.gowrap1()
      /home/runner/go/pkg/mod/github.com/pb33f/[email protected]/index/rolodex.go:301 +0xa4
@informalict
Copy link
Author

BTW please run your tests with go test -race so then you will see probably more DATA RACE

@daveshanley daveshanley added the bug Something isn't working label Jan 24, 2025
@daveshanley
Copy link
Member

I am aware of this. Thank you for reporting however.

@daveshanley
Copy link
Member

I have put some cycles into this, but it goes pretty deep, it's not a trivial thing to fix.

@AtomicTroop
Copy link

AtomicTroop commented Feb 19, 2025

Just ran into this too. As a temporary workaround, setting ExtractRefsSequentially to true in your DocumentConfiguration sidesteps the issue in exchange for a reasonable performance hit.

In any case, it keeps our spec validation tests from failing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants