Go plugin compilation issue with Nakama 3.9.0

I updated my local setup to Nakama 3.9.0 via the Mac binary at https://github.com/heroiclabs/nakama/releases and updated the common library to the recommended:

% env GO111MODULE=on go get "github.com/heroiclabs/nakama-common/runtime@v1.20.0"
% go mod vendor
% go build --trimpath --mod=vendor --buildmode=plugin -o foo.so
% cp foo.so ..../nakama-3.9.0/data/modules

When starting I however get:

...
{"level":"error","ts":"2021-11-04T10:29:15.799+0200","caller":"server/runtime_go.go:2492","msg":"Could not open Go module","path":".../nakama-3.9.0/data/modules/....so","error":"plugin.Open(\.../nakama-3.9.0/data/modules/foo.so\"): plugin was built with a different version of package google.golang.org/protobuf/internal/detrand"}
{"level":"error","ts":"2021-11-04T10:29:15.799+0200","caller":"server/runtime.go:585","msg":"Error initialising Go runtime provider","error":"plugin.Open(\".../nakama-3.9.0/data/modules/foo.so\"): plugin was built with a different version of package google.golang.org/protobuf/internal/detrand"}
{"level":"fatal","ts":"2021-11-04T10:29:15.799+0200","caller":"v3/main.go:146","msg":"Failed initializing runtime modules","error":"plugin.Open(\".../nakama-3.9.0/data/modules/foo.so\"): plugin was built with a different version of package google.golang.org/protobuf/internal/detrand"}

My go.mod for the plugin looks like:

module towersnap

go 1.17

require (
	github.com/golang/protobuf v1.5.0
	github.com/heroiclabs/nakama-common v1.20.0
	golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
	google.golang.org/protobuf v1.26.0
)

I removed a couple irrelevant modules. The protobuf and sync requirements are added automatically by Go based on resolved dependencies, I guess. I’m not too experienced with Go yet. If I remove all requirements except nakama-common they get added back in at these versions.

Seems the server has somehow different versions than these?

@chakie I recommend you read through the Go dependency pinning docs. This part is especially important in your case I think:

Note

It may help you to identify the correct version of a transitive dependency to be pinned in your plugin go.mod file by searching Nakama’s vendor/modules.txt file and look for the package that lead to the error.

Thank you @zyro , that fixed my build. I didn’t think about looking in your Git repo for what Nakama was using. TIL. :slight_smile:

@chakie No problem, glad it’s solved!

For future reference the best way to stay on top of this is to keep an eye on the Nakama releases page. We call out dependency upgrades in the release notes, so you can use that as a cue to check your own dependency usage in case it needs changes. :+1:

Yeah, I do check them thoroughly, as they mention the required Go and nakama-common versions. Having those correct had been enough so far, thus my panicked question.

Hi @chakie , can you teach me how can you solve this problem, please?

@mautoan11 What problem do you have? Do you use the same version of Go as mentioned in the release notes?