Skip to content

Import of gnostic-models and gnostic generated code leads to panic #397

@pkwarren

Description

@pkwarren

We've encountered an issue in recent versions of upstream libraries that mix dependencies - sometimes pulling in gnostic and other times gnostic-models. This leads to a panic at runtime, and it causes golangci-lint to fail with an internal error.

Here's a small example program illustrating the panic:

package main

import (
	"log"

	_ "github.com/google/gnostic-models/openapiv2"
	_ "github.com/google/gnostic/openapiv2"
)

func main() {
	log.Println("hello world")
}

This leads to a panic:

panic: proto: file "extensions/extension.proto" is already registered
        previously from: "github.com/google/gnostic-models/extensions"
        currently from:  "github.com/google/gnostic/extensions"
See https://protobuf.dev/reference/go/faq#namespace-conflict


goroutine 1 [running]:
google.golang.org/protobuf/reflect/protoregistry.glob..func1({0x102932c68?, 0x1400010b180?}, {0x102932c68?, 0x1400010b1c0})
        /Users/pkw/go/pkg/mod/google.golang.org/protobuf@v1.30.0/reflect/protoregistry/registry.go:56 +0x200
google.golang.org/protobuf/reflect/protoregistry.(*Files).RegisterFile(0x14000114060, {0x1029396a0?, 0x14000119340?})
        /Users/pkw/go/pkg/mod/google.golang.org/protobuf@v1.30.0/reflect/protoregistry/registry.go:130 +0x314
google.golang.org/protobuf/internal/filedesc.Builder.Build({{0x102872ea6, 0x24}, {0x102bf5aa0, 0x282, 0x282}, 0x0, 0x4, 0x0, 0x0, {0x102934758, ...}, ...})
        /Users/pkw/go/pkg/mod/google.golang.org/protobuf@v1.30.0/internal/filedesc/build.go:112 +0x1a8
google.golang.org/protobuf/internal/filetype.Builder.Build({{{0x102872ea6, 0x24}, {0x102bf5aa0, 0x282, 0x282}, 0x0, 0x4, 0x0, 0x0, {0x0, ...}, ...}, ...})
        /Users/pkw/go/pkg/mod/google.golang.org/protobuf@v1.30.0/internal/filetype/build.go:138 +0x17c
github.com/google/gnostic/extensions.file_extensions_extension_proto_init()
        /Users/pkw/go/pkg/mod/github.com/google/gnostic@v0.6.9/extensions/extension.pb.go:456 +0x178
github.com/google/gnostic/extensions.init.0()

Generated code should ideally only live in a single place - is it possible to update gnostic to pull generated code from gnostic-models so that it only exists in one go module?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions