Skip to content

fix: use proto.Merge instead of value assignment in opaque API mode#6384

Closed
clarabennettdev wants to merge 1 commit intogrpc-ecosystem:mainfrom
clarabennettdev:fix/opaque-api-copylocks
Closed

fix: use proto.Merge instead of value assignment in opaque API mode#6384
clarabennettdev wants to merge 1 commit intogrpc-ecosystem:mainfrom
clarabennettdev:fix/opaque-api-copylocks

Conversation

@clarabennettdev
Copy link
Copy Markdown

Fixes #6380

Summary

When use_opaque_api=true, the generated *.pb.gw.go files contain value assignments (protoReq = bodyData) that copy protoimpl.MessageState, which embeds sync.Mutex via noCopy. This triggers go vet copylocks violations.

Changes

Replaced all 4 occurrences of protoReq = bodyData with proto.Merge(&protoReq, &bodyData) in protoc-gen-grpc-gateway/internal/gengateway/template.go:

  • Request handler (non-fieldmask, body="*")
  • Request handler (fieldmask, body="*")
  • Local request handler (non-fieldmask, body="*")
  • Local request handler (fieldmask, body="*")

proto is already imported in generated code via generator.go, so no import changes needed.

All existing tests pass.

Fixes #6380

When use_opaque_api=true, the generated code copies proto messages by
value (protoReq = bodyData), which copies the sync.Mutex embedded in
protoimpl.MessageState and triggers go vet copylocks.

Replace all 4 occurrences of value assignment with proto.Merge in both
request and local request handler templates.
@johanbrandhorst
Copy link
Copy Markdown
Collaborator

Thanks for this, looks like a dupe of #6383?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

use_opaque_api=true: generated code copies proto message by value (go vet copylocks violation)

2 participants