hashicorp / go-plugin

Golang plugin system over RPC.
Mozilla Public License 2.0
5.25k stars 450 forks source link

Reattach in tests with versioned plugins #310

Open lovromazgon opened 4 months ago

lovromazgon commented 4 months ago

I've got a test that runs the plugin server in a goroutine and fetches the reattach config from the server using ServeTestConfig.ReattachConfigCh, passing it to the client. The problem is that the server and client are versioned, so the client config has a map of VersionedPlugins while Plugins is empty. When the client is created using the reattach config, Client.Start exits early by calling c.reattach(), skipping the part where the plugin version is determined and leaving ClientConfig.Plugins set to nil. The client is therefore not initialized correctly and can't be used.

I found that executing the version handshake when reattaching solves my problem. Before opening a PR I wanted to ask if this is the proper way to address this issue, or if I'm missing something else.

https://github.com/lovromazgon/go-plugin/commit/a3d2cd05877f166c51114af75260faece61863f9

image