google / google/gnostic-models

OpenAPIv2.go and OpenAPIv3.go both copy mutexes, generating racy code

Open
#9 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
20
Forks
11
PR merge metrics
No merged PRs in 30d

Description

It seems like the openapiv2 and openapiv3 codebases include generated code that violates the [Go copylock code analysis](https://pkg.go.dev/golang.org/x/tools/go/analysis/passes/copylock). (That code analysis checks to make sure that sync.Mutex is used with a pointer and isn't copied by value, rendering it unable to protect data.)

That code seems to be generated, so it might be a bug in the generator (I believe protoc-gen-go includes those sync.Mutex's explicitly to keep MessageState from being copied like this).

The errors look like:

```
openapiv2/OpenAPIv2.go:5872:10: assignment copies lock value to *m: github.com/google/gnostic-models/openapiv2.JsonReference contains google.golang.org/protobuf/internal/impl.MessageState contains sync.Mutex (copylocks)
openapiv2/OpenAPIv2.go:6248:11: assignment copies lock value to *m: github.com/google/gnostic-models/openapiv2.ParametersItem contains google.golang.org/protobuf/internal/impl.MessageState contains sync.Mutex (copylocks)
openapiv2/OpenAPIv2.go:6268:10: assignment copies lock value to *m: github.com/google/gnostic-models/openapiv2.PathItem contains google.golang.org/protobuf/internal/impl.MessageState contains sync.Mutex (copylocks)
openapiv2/OpenAPIv2.go:6542:11: assignment copies lock value to *m: github.com/google/gnostic-models/openapiv2.ResponseValue contains google.golang.org/protobuf/internal/impl.MessageState contains sync.Mutex (copylocks)
openapiv2/OpenAPIv2.go:6584:10: assignment copies lock value to *m: github.com/google/gnostic-models/openapiv2.Schema contains google.golang.org/protobuf/internal/impl.MessageState contains sync.Mutex (copylocks)
```

and

```
openapiv3/OpenAPIv3.go:6085:10: assignment copies lock value to *m: github.com/google/gnostic-models/openapiv3.PathItem contains google.golang.org/protobuf/internal/impl.MessageState contains sync.Mutex (copylocks)
openapiv3/OpenAPIv3.go:6213:10: assignment copies lock value to *m: github.com/google/gnostic-models/openapiv3.Reference contains google.golang.org/protobuf/internal/impl.MessageState contains sync.Mutex (copylocks)
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.