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 load plugin when other dependent packages changed #20554

Closed
davyxu opened this issue Jun 2, 2017 · 1 comment
Closed

plugin: cannot load plugin when other dependent packages changed #20554

davyxu opened this issue Jun 2, 2017 · 1 comment

Comments

@davyxu
Copy link

davyxu commented Jun 2, 2017

Please answer these questions before submitting your issue. Thanks!

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

1.8.3

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

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/root/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build438394725=/tmp/go-build"
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 fake code:

func OnPluginInit( ){
      
      pluginpkg.Foo( )
}

package 'pluginpkg' fake code

func Foo( ){
      println( "v1")

     // println("v2")
}

go build plugin to 'v1.so'
uncomment // println("v2") then go build plugin to v2.so

host loader fake code:

func main(){

    loadPlugin( "v1.so")

    loadPlugin( "v2.so")
}

What did you expect to see?

console output:
(after v1.so loaded)
v1

(after v2.so loaded)
v1
v2

What did you see instead?

console output:
(after v1.so loaded)
v1

(after v2.so loaded)
plugin was built with a different version of package v2

I'm using golang plugin system in MMO game server. We need use plugin system to hot fix program when server is still running.

I guess that plugin system can ONLY hot fix plugin's main package,BUT other depend packages

I've read #17832 issue, and know it's hard to make code compatible in plugin.

It's hard to make all code write in one plugin main package in order to hot fix
So, how can I make plugin and all it's depend packages hot fix with plugin system?

Thank you!

@odeke-em odeke-em changed the title plugin: Can not load plugin when other dependent packages changed plugin: cannot load plugin when other dependent packages changed Jun 3, 2017
@crawshaw
Copy link
Member

crawshaw commented Sep 2, 2017

I see no way around this. Beyond the practical issue that using the dynamic loader to hot-swap code is extremely difficult, there are definitional issues. What if the init functions have changed between versions of a package? They can't be called again. What if a global variable already being used by running code changes type or is removed?

For your specific problem, consider introducing an interface type registered with a control package. When a new plugin is loaded, remove the implementation of the interface that comes from the old plugin, and add the implementation that comes from the new plugin. This lets you hot-swap running code (though you are slowly accumulating all previous versions into the process).

@crawshaw crawshaw closed this as completed Sep 2, 2017
@golang golang locked and limited conversation to collaborators Sep 2, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants