eh-steve / goloader

Compile, load and run Go code at runtime.
Apache License 2.0
51 stars 4 forks source link

found another firstmodule type that wasn't registered by goloader. #20

Closed nnnnt21 closed 1 year ago

nnnnt21 commented 1 year ago

I keep running into this error:

[found another firstmodule type that wasn't registered by goloader. Symbol name:

Full error](panic: found another firstmodule type that wasn't registered by goloader. Symbol name: type:go.shape.interface { Close() error; Position() github.com/go-gl/mathgl/mgl64.Vec3; Rotation() github.com/df-mc/dragonfly/server/block/cube.Rotation; Type() github.com/df-mc/dragonfly/server/world.EntityType; World() github.com/df-mc/dragonfly/server/world.World }, type name: go.shape.interface { Close() error; Position() github.com/go-gl/mathgl/mgl64.Vec3; Rotation() github.com/df-mc/dragonfly/server/block/cube.Rotation; Type() github.com/df-mc/dragonfly/server/world.EntityType; World() github.com/df-mc/dragonfly/server/world.World }. This shouldn't be possible and indicates a bug in firstmodule type registration)

Is there something I am doing wrong here? Or are my dependencies really breaking it all? Here is my loader

func (bl *BridgeLayer) LoadPlugin() {
    conf := jit.BuildConfig{
        KeepTempFiles:   false,
        ExtraBuildFlags: []string{"-x"},
        BuildEnv:        nil,
        TmpDir:          "",
        DebugLog:        true,
    }

    loadable, err := jit.BuildGoFiles(conf, "resources/plugins/coretest.go")

    if err != nil {
        panic(err)
    }

    module, err := loadable.Load()
    if err != nil {
        panic(err)
    }

    symbols := module.SymbolsByPkg[loadable.ImportPath]

    defer func() {
        err = module.Unload()
        if err != nil {
            fmt.Println(err)
            panic(err)
        }
    }()

    switch f := symbols["New"].(type) {
    case func() interface{}:
        pl := f()

        fmt.Println("Loaded first plugin")
        fmt.Println(pl)
    default:
        panic("Function signature was not what was expected")
    }
}

And here is my plugin

package coretestplugin

import (
    "github.com/nnnnt21/drag/plugins"
)

type CorePluginTest struct {
}

func (c CorePluginTest) Initialize(api plugins.ServerAPI) {
    //TODO implement me
    panic("implement me")
}

func (c CorePluginTest) OnPlayerJoin(player plugins.Player) {
    //TODO implement me
    panic("implement me")
}

func (c CorePluginTest) OnPlayerLeave(player plugins.Player) {
    //TODO implement me
    panic("implement me")
}

func New() interface{} {
    return CorePluginTest{}
}

var _ plugins.Plugin = (*CorePluginTest)(nil)

Could anyone provide me with some insight?

eh-steve commented 1 year ago

Hi, thanks for raising an issue - this panic was intended to flag failure cases (to me) where the type registration logic is faulty.

Would you mind posting the actual imports that cause this so I can reproduce/add a test case for it?

nnnnt21 commented 1 year ago

I am not really sure how to tell what module is causing it but i've attached the debug log below and here is my go.mod file if that is what your after

module github.com/nnnnt21/drag

go 1.20

require (
    github.com/df-mc/dragonfly v0.9.8
    github.com/eh-steve/goloader/jit v0.0.0-20230701235027-e554af95fe68
    github.com/google/uuid v1.3.0
    github.com/pelletier/go-toml v1.9.5
    github.com/sirupsen/logrus v1.9.0
)

require (
    github.com/brentp/intintmap v0.0.0-20190211203843-30dc0ade9af9 // indirect
    github.com/cespare/xxhash v1.1.0 // indirect
    github.com/df-mc/atomic v1.10.0 // indirect
    github.com/df-mc/goleveldb v1.1.9 // indirect
    github.com/df-mc/worldupgrader v1.0.8 // indirect
    github.com/eh-steve/goloader v0.0.0-20230701235027-e554af95fe68 // indirect
    github.com/go-gl/mathgl v1.0.0 // indirect
    github.com/golang/protobuf v1.5.3 // indirect
    github.com/golang/snappy v0.0.4 // indirect
    github.com/klauspost/compress v1.15.15 // indirect
    github.com/muhammadmuzzammil1998/jsonc v1.0.0 // indirect
    github.com/rogpeppe/go-internal v1.9.0 // indirect
    github.com/sandertv/go-raknet v1.12.0 // indirect
    github.com/sandertv/gophertunnel v1.31.0 // indirect
    github.com/stretchr/testify v1.8.4 // indirect
    go.uber.org/atomic v1.10.0 // indirect
    golang.org/x/crypto v0.5.0 // indirect
    golang.org/x/exp v0.0.0-20230206171751-46f607a40771 // indirect
    golang.org/x/image v0.5.0 // indirect
    golang.org/x/net v0.7.0 // indirect
    golang.org/x/oauth2 v0.4.0 // indirect
    golang.org/x/sys v0.5.0 // indirect
    golang.org/x/text v0.7.0 // indirect
    google.golang.org/appengine v1.6.7 // indirect
    google.golang.org/protobuf v1.31.0 // indirect
    gopkg.in/square/go-jose.v2 v2.6.0 // indirect
)

log.txt

eh-steve commented 1 year ago

I was looking for the minimal reproducing source of the JIT code that causes this issue (i.e. whatever is in nnnnt/drag/plugins).

I need to be able to build the package which defines the interface


type X interface { 
    Close() error
    Position() mgl64.Vec3; 
    Rotation() cube.Rotation
    Type() world.EntityType
    World() *world.World 
}

to see what the symbol name should be.

eh-steve commented 1 year ago

Actually, there's a small chance I already fixed this in this PR which I haven't merged yet. Would you mind testing using aeda36ba1edee31cf00bd37d88724ef51f2529ea?

nnnnt21 commented 1 year ago

I apologize, that struct actually is from the github.com/df-mc/dragonfly/server/player package i believe, as I don't define that anywhere. But in good news that PR actually did fix the issue, I appreciate it a ton.

eh-steve commented 1 year ago

Just a heads up that I might be rebasing that branch while I finish it off and will delete it once it's merged, so you might need to point at master again once I'm done

eh-steve commented 1 year ago

FYI I've just merged that PR into master now 🙂