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: cannot reload .so of the same path #17980

Closed
reusee opened this issue Nov 18, 2016 · 4 comments
Closed

plugin: cannot reload .so of the same path #17980

reusee opened this issue Nov 18, 2016 · 4 comments
Labels
FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Milestone

Comments

@reusee
Copy link

reusee commented Nov 18, 2016

What did you do?

main.go

package main

import (
	"fmt"
	"os"
	"os/exec"
	"plugin"
)

func main() {
	output, err := exec.Command("go", "build", "-buildmode=plugin", "-o=bar.so", "bar.go").CombinedOutput()
	if err != nil {
		fmt.Printf("%s\n", output)
		panic(err)
	}

	p, err := plugin.Open("bar.so")
	if err != nil {
		panic(err)
	}
	f, err := p.Lookup("Fn")
	if err != nil {
		panic(err)
	}
	f.(func())()

	// build bar2.go
	err = os.Remove("bar.so")
	if err != nil {
		panic(err)
	}
	output, err = exec.Command("go", "build", "-buildmode=plugin", "-o=bar.so", "bar2.go").CombinedOutput()
	if err != nil {
		fmt.Printf("%s\n", output)
		panic(err)
	}

	// reload
	p, err = plugin.Open("bar.so")
	if err != nil {
		panic(err)
	}
	f, err = p.Lookup("Fn")
	if err != nil {
		panic(err)
	}
	f.(func())()

}

bar.go

package main

func Fn() {
	println("bar1")
}

bar2.go

package main

func Fn() {
	println("bar2")
}

run

go run main.go

What did you expect to see?

bar1
bar2

or throw error on the second Open call.

What did you see instead?

bar1
bar1

System details

go version devel +120cf67 Fri Nov 18 17:25:07 2016 +0000 linux/amd64
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/reus"
GORACE=""
GOROOT="/home/reus/go"
GOTOOLDIR="/home/reus/go/pkg/tool/linux_amd64"
TERM="dumb"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build816756848=/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"
GOROOT/bin/go version: go version devel +120cf67 Fri Nov 18 17:25:07 2016 +0000 linux/amd64
GOROOT/bin/go tool compile -V: compile version devel +120cf67 Fri Nov 18 17:25:07 2016 +0000 X:framepointer
uname -sr: Linux 4.8.7-1-ARCH
/usr/lib/libc.so.6: GNU C Library (GNU libc) stable release version 2.24, by Roland McGrath et al.
gdb --version: GNU gdb (GDB) 7.12
@ianlancetaylor ianlancetaylor added this to the Go1.8Maybe milestone Nov 18, 2016
@quentinmit quentinmit added the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label Nov 18, 2016
@minux
Copy link
Member

minux commented Nov 18, 2016 via email

@amenzhinsky
Copy link
Contributor

@minux that's not the case, we can load multiple fPIC libraries with the same name. The issue caused by caching https://github.com/golang/go/blob/master/src/plugin/plugin_dlopen.go#L134

@crawshaw
Copy link
Member

crawshaw commented Dec 3, 2016

@amenzhinsky I tested this on both darwin and linux, and @minix appears to be correct.

If I:

C.dlopen("plugin1.so") // returns handle h1
os.Remove("plugin1.so")
os.Rename("plugin2.so", "plugin1.so")
C.dlopen("plugin1.so") // returns handle h1

That is, plugin2.so is not opened. So doing the right thing here, returning an error on a second open of a .so that has changed, is tricky because dlopen won't do the work for us. We could do something fancier like taking a sha1 of the file first, but I don't think it's worth it for 1.8.

(I definitely do not think we should support opening a different plugin with the same path, given we don't close plugins.)

@crawshaw crawshaw modified the milestones: Go1.9, Go1.8Maybe Dec 3, 2016
@bradfitz bradfitz modified the milestones: Go1.9, Go1.10 Jun 7, 2017
@rsc
Copy link
Contributor

rsc commented Dec 4, 2017

Given comments by @minux and @crawshaw seems like this is working as intended or at least working as best it possibly can.

@rsc rsc closed this as completed Dec 4, 2017
@golang golang locked and limited conversation to collaborators Dec 4, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Projects
None yet
Development

No branches or pull requests

9 participants