Skip to content

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

Closed
@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/[email protected]/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/[email protected]/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/[email protected]/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/[email protected]/internal/filetype/build.go:138 +0x17c
github.com/google/gnostic/extensions.file_extensions_extension_proto_init()
        /Users/pkw/go/pkg/mod/github.com/google/[email protected]/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

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions