Version mismatch between vendored version of dependency and normal version

At Dgraph, we use gRPC for communication between the server and our Go client. Now if someone tries to use our Go client in their project, they get this error

./main.go:55: cannot use conn (type *"google.golang.org/grpc".ClientConn) as type *"github.com/dgraph-io/dgraph/vendor/google.golang.org/grpc".ClientConn in argument to graph.NewDgraphClient
./main.go:122: cannot use conn (type *"google.golang.org/grpc".ClientConn) as type *"github.com/dgraph-io/dgraph/vendor/google.golang.org/grpc".ClientConn in argument to graph.NewDgraphClient

because Go considers the version of gRPC that is vendored in with Dgraph and the one in your GOPATH to be different even if it is the same.

Is there any way to get around this, apart from not vendoring in the grpc dependency?

You can find more details about the issue at https://discuss.dgraph.io/t/goclient-and-vendor-mismatch-issues/1166

Thanks,
Pawan

Sorry, no. This is the archillies heal of the vendor/ feature, it’s only for end user projects, it cannot be used safely by library authors.

Thanks for looking at it @dfc. Actually Dgraph itself is a server and not a library and thus would be used directly by end users. It has gRPC vendored in.

Though when I try to use it with the client which is a library (it does not have gRPC vendored), I get this error.

Another interesting thing is that if someones forks Dgraph into their own repo, it doesn’t build and has a bunch of errors. Any ideas why that might be happening?

It’s a bit hard to talk about this because the term library is imprecise.

I looks like you have a repository which depends on the dgraph code, and the dgraph code has vendored grpc. This is what is breaking.

If you delete dgraphs copy of grpc, it should compile

That’s right. I figured out that if delete the vendored gRPC copy in Dgraph, nothing breaks. Is that the only solution here?

Yes. The source of a package must only exist once per compiled binary or you get weird stuff like this, type equality being broken, happening.

2 Likes

Thanks @dfc.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.