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

plugin: with net/http causes "plugin was built with a different version of package" #20248

Closed
jb613 opened this issue May 4, 2017 · 9 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@jb613
Copy link

jb613 commented May 4, 2017

What version of Go are you using (go version)?

go version go1.8.1 linux/386

What operating system and processor architecture are you using (go env)?

GOARCH="386"
GOBIN=""
GOEXE=""
GOHOSTARCH="386"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/root/Go/_lib"
GORACE=""
GOROOT="/root/go"
GOTOOLDIR="/root/go/pkg/tool/linux_386"
GCCGO="gccgo"
GO386=""
CC="gcc"
GOGCCFLAGS="-fPIC -m32 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build202967868=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"

What did you do?

plugin.go:
package main

import (
	"net/http"
)

func fooPlugin() {
	_ = &http.Request{}
}

main.go:
package main

import (
	"log"
	"net/http"
	"plugin"
)

func foo() {
	_ = &http.Request{}
}

func main() {
	foo()

	pg, err := plugin.Open("./plugin.so")
	if err != nil {
		log.Printf("Could not open plugin: %s", err)
		return
	}
	log.Printf("pg=%+v\n", pg)
}

go build -buildmode=plugin -o plugin.so plugin.go
go run main.go

If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.

What did you expect to see?

pg=...something...

What did you see instead?

2017/05/04 12:34:36 Could not open plugin: plugin.Open: plugin was built with a different version of package vendor/golang_org/x/text/unicode/norm

@crawshaw
Copy link
Member

crawshaw commented May 4, 2017

This generally works. The only thing that looks different in your report than my local tests is GOARCH=386. I'll give that a try when next I can.

@bradfitz bradfitz changed the title plugin with net/http causes "plugin was built with a different version of package" plugin: with net/http causes "plugin was built with a different version of package" May 4, 2017
@bradfitz bradfitz added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label May 4, 2017
@bradfitz bradfitz added this to the Go1.10 milestone May 4, 2017
@jb613
Copy link
Author

jb613 commented May 5, 2017

It works until I import net/http in the plugin - then plugin.Open fails.

My system is 32-bit Linux. I also just tried the following:

GOARCH= go build -buildmode=plugin -o plugin.so plugin.go
GOARCH= go run main.go

with same result:

2017/05/05 00:25:33 Could not open plugin: plugin.Open: plugin was built with a different version of package vendor/golang_org/x/text/unicode/norm

@bradfitz
Copy link
Contributor

bradfitz commented May 5, 2017

I don't think this has anything to do with net/http. I bet importing any cgo package is what causes the failure. Try os/user or net, for example.

@jb613
Copy link
Author

jb613 commented May 5, 2017

No, it looks to be something with net/http. I tried 2 plugins - 1 importing "net" and the other importing "os/user" and plugin.Open() succeeded.

net:

package main

import (
	"net"
)

func fooPlugin() {
	_, err := net.Dial("tcp", "golang.org:80")
	if err != nil {
		panic(err)
	}
}

os/user:

package main

import (
	"os/user"
)

func fooPlugin() {
	_, err := user.Current()
	if err != nil {
		panic(err)
	}
}

I suspect something to do with the combination of:

  • 32-bit Linux
  • go 1.8.1 vendor/golang_org/x/text/unicode/norm
  • net/http

@MTRNord
Copy link

MTRNord commented Aug 10, 2017

I got a similiar problem with a another local package. It looks like:

// Original Code from https://github.com/matrix-org/go-neb/blob/b1fe968f832996c219dfb60d718d36220ef3c91c/src/github.com/matrix-org/go-neb/types/service.go
// It is LICENSED under Apache 2.0
package types

// A Service is the configuration for a bot service.
type Plugin interface {
	// Return the user ID of this service.
	PluginID() string
	// Return if Service requires Web.
	Web() bool
}

// DefaultPlugin NO-OPs the implementation of optional Plugin interface methods. Feel free to override them.
type DefaultPlugin struct {
	id  string
	web bool
}

// NewDefaultPlugin creates a new Plugin with implementations for pluginID(), serviceName() and web()
func NewDefaultPlugin(pluginID string, web bool) DefaultPlugin {
	return DefaultPlugin{pluginID, web}
}

func (s *DefaultPlugin) PluginID() string {
	return s.id
}

func (s *DefaultPlugin) Web() bool {
	return s.web
}

and gets imported into the file I use it in and imported in my main function that I use to run the plugin from. both are compiled directly after each other.

Plugin Code:

package main

import (
	"fmt"
	"gitlab.com/IRSH/irshGoFramework/types"
)

// pluginName of the Web Plugin
const pluginName = "web"

type pluginStruct struct {
	types.DefaultPlugin
}

func (g pluginStruct) Greet() {
	fmt.Println("Hello Universe")
}

// Define Plugin (Web=false as it otherwise would create a dependency loop)
var Plugin = &pluginStruct{
	DefaultPlugin: types.NewDefaultPlugin(pluginName, false),
}

Main/Loader Code:

package main

import (
	"fmt"
	"gitlab.com/IRSH/irshGoFramework/types"
	"os"
	"plugin"
)

func main() {
		plug, err := plugin.Open("./plugins/web.so")
		if err != nil {
			fmt.Println(err)
			os.Exit(1)
		}

		// 2. look up a symbol (an exported function or variable)
		// in this case, variable Greeter
		symGreeter, err := plug.Lookup("Plugin")
		if err != nil {
			fmt.Println(err)
			os.Exit(1)
		}

		// 3. Assert that loaded symbol is of a desired type
		// in this case interface type Greeter (defined above)
		var pluginModule types.Plugin
		pluginModule, ok := symGreeter.(types.Plugin)
		if !ok {
			fmt.Println("unexpected type from module symbol")
			os.Exit(1)
		}

		// 4. use the module
		fmt.Println(pluginModule.PluginID())
}

Edit: My go env output:

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/marcel/go"
GORACE=""
GOROOT="/home/marcel/sdk/go1.9rc2"
GOTOOLDIR="/home/marcel/sdk/go1.9rc2/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build216203164=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"

@lni
Copy link

lni commented Aug 11, 2017

I am having a similar issue when testing go 1.9rc2 (same as the user above).

The plugin part of the software I am working on works fine when using go 1.8.3, once switched to go1.9rc2 while keeping everything else the same (3rd party libraries all vendored, no exact env setting, pretty sure everything is using default value), I got the "plugin was built with a different version of package plugin" error when trying to open the plugin.

As @bradfitz mentioned above, the plugin I am trying to build does import a package that uses cgo.

@crawshaw
Copy link
Member

crawshaw commented Sep 3, 2017

@lni want to try out https://golang.org/cl/61071 and see if it helps?

@crawshaw
Copy link
Member

I believe this was fixed at tip by https://golang.org/cl/63693. It's a little concerning that the original report mentions 1.8, however I haven't been able to replicate that bug at HEAD.

Please comment if you're still seeing this with HEAD and I'll reopen this.

@tarndt
Copy link

tarndt commented Oct 19, 2017

@crawshaw I am confirming, but it looks like I am hitting this on 1.8.3. Upgrading right now isn't an option (our systems crash on 1.9 due to some threading issues). It looks like I'll need to backport the above CL 😿 to 1.8...

@golang golang locked and limited conversation to collaborators Oct 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

7 participants