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

Use custom listener when serving plugin #213

Open
Anthony-Jhoiro opened this issue Sep 24, 2022 · 1 comment
Open

Use custom listener when serving plugin #213

Anthony-Jhoiro opened this issue Sep 24, 2022 · 1 comment

Comments

@Anthony-Jhoiro
Copy link

I really enjoy using this package, but I encountered a limitation when trying to serve plugins that listen on TCP instead than with UNIX sockets due to security limitations.

The Serve function, as shown in the examples, seems only to create UNIX sockets listeners when running on non-windows system.

I tried a few things, first with a manually created server like this :

listener, err := net.Listen("tcp", ":12345")
if err != nil { panic(err) }

server := plugin.GRPCServer{
     // ...plugin config
}

err = server.Init()
if err != nil { panic(err) }

server.Serve(listener)

But I encountered an issue with the logger, as it is not initialized in the server.Init function, so the program crashes anytime, it tries to log with a segmentation error.

I made it work by adding a field for a custom listener in the ServeConfig struct (server.go:58) and preventing calling the serverListener() function in the Serve function. This way I can use the TCP listener like this :

listener, err := net.Listen("tcp", ":12345")
if err != nil {
    panic(err)
}

plugin.Serve(&plugin.ServeConfig{
    // ...plugin config
    Listener:   listener,
})

And this seems to be working fine.

I am not sure to fully understand this library that's why I didn't make a PR about this now. Is there another planned way of doing that? I can do a PR about it if needed.
If it helps, you can find my fork here : https://github.com/Anthony-Jhoiro/go-plugin/tree/feat/serve_custom_listener

I am using the latest package version and go 1.18.3 btw.
Thanks a lot !

@Anthony-Jhoiro Anthony-Jhoiro changed the title Use custom listener when serving Use custom listener when serving plugin Sep 24, 2022
@davestibrany-dd
Copy link

+1 this would be very useful, or even just providing us with a way to configure tcp/unix sockets in ServeConfig.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants