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

datastore: protobuf namespace conflict with google.golang.org/appengine/v2 #10155

Closed
sg0hsmt opened this issue May 12, 2024 · 2 comments · Fixed by #10158
Closed

datastore: protobuf namespace conflict with google.golang.org/appengine/v2 #10155

sg0hsmt opened this issue May 12, 2024 · 2 comments · Fixed by #10158
Assignees
Labels
api: datastore Issues related to the Datastore API. triage me I really want to be triaged.

Comments

@sg0hsmt
Copy link

sg0hsmt commented May 12, 2024

Client

datastore

Environment

Go executable on Linux

Go Environment

$ go version
go version go1.22.3 linux/amd64
$ go env
GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/vscode/.cache/go-build'
GOENV='/home/vscode/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='local'
GOTOOLDIR='/usr/local/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.22.3'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/workspaces/namespace-conflict/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build3064827702=/tmp/go-build -gno-record-gcc-switches'

Code

package main

import (
	"fmt"

	_ "cloud.google.com/go/datastore"
	_ "google.golang.org/appengine/v2"
)

func main() {
	fmt.Println("Hello, World!")
}

Expected behavior

Hello, World! will be displayed.

Actual behavior

A panic will occur.

$ go run main.go 
panic: proto: file "datastore_v3.proto" is already registered
        previously from: "cloud.google.com/go/datastore/internal/gaepb"
        currently from:  "google.golang.org/appengine/v2/internal/datastore"
See https://protobuf.dev/reference/go/faq#namespace-conflict


goroutine 1 [running]:
google.golang.org/protobuf/reflect/protoregistry.init.func1({0x101aa60?, 0xabafe0?}, {0xba6a80, 0xc000036ee0})
        /go/pkg/mod/google.golang.org/[email protected]/reflect/protoregistry/registry.go:56 +0x1ec
google.golang.org/protobuf/reflect/protoregistry.(*Files).RegisterFile(0xc0000122e8, {0xbb48a0, 0xc00019ee00})
        /go/pkg/mod/google.golang.org/[email protected]/reflect/protoregistry/registry.go:130 +0xbc3
google.golang.org/protobuf/internal/filedesc.Builder.Build({{0x97faf0, 0x31}, {0xff81e0, 0x2d00, 0x2d00}, 0xc, 0x37, 0x0, 0x0, {0xbab380, ...}, ...})
        /go/pkg/mod/google.golang.org/[email protected]/internal/filedesc/build.go:112 +0x1d6
google.golang.org/protobuf/internal/filetype.Builder.Build({{{0x97faf0, 0x31}, {0xff81e0, 0x2d00, 0x2d00}, 0xc, 0x37, 0x0, 0x0, {0x0, ...}, ...}, ...})
        /go/pkg/mod/google.golang.org/[email protected]/internal/filetype/build.go:138 +0x17d
google.golang.org/appengine/v2/internal/datastore.file_datastore_v3_proto_init()
        /go/pkg/mod/google.golang.org/appengine/[email protected]/internal/datastore/datastore_v3.pb.go:6420 +0x1b8
google.golang.org/appengine/v2/internal/datastore.init.0()
        /go/pkg/mod/google.golang.org/appengine/[email protected]/internal/datastore/datastore_v3.pb.go:5739 +0xf
exit status 2

Additional context

Importing google.golang.org/appengine/v2 with datastore v1.16.0 or later causes a protobuf namespace conflict.

related: #7760, #9744

@sg0hsmt sg0hsmt added the triage me I really want to be triaged. label May 12, 2024
@product-auto-label product-auto-label bot added the api: datastore Issues related to the Datastore API. label May 12, 2024
codyoss added a commit to codyoss/google-cloud-go that referenced this issue May 13, 2024
The namespace and filename need to be different than the file
these were copied and regenerated from to make the proto registry
not error out on initialization.

Fixes: googleapis#10155
@noahdietz
Copy link
Contributor

@sg0hsmt thanks for reporting this. It looks like @codyoss has a potential fix out, but it has some risks. We will continue to consider that, but in the meantime, the Protobuf documentation has some workarounds at the application level, but runtime and build time mitigations: https://protobuf.dev/reference/go/faq/#fix-namespace-conflict

Can you try one of those? Will that work for the time being? Thanks.

@noahdietz
Copy link
Contributor

We are going to move forward with Cody's change to deal with the issue.

gcf-merge-on-green bot pushed a commit that referenced this issue May 13, 2024
The namespace and filename need to be different than the file these were copied and regenerated from to make the proto registry not error out on initialization.

Usually it is not good to use a new package name in protos but I believe it is fine here since these are just simple message types being declared and not a service.

Fixes: #10155
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: datastore Issues related to the Datastore API. triage me I really want to be triaged.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants