hashicorp / hashicorp/go-plugin

Reattach in tests with versioned plugins

Open
#310 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
6.1k
Forks
511
Avg merge
22h 47m
Merged PRs (30d)
4

Description

I've got a test that runs the plugin server in a goroutine and fetches the reattach config from the server using [`ServeTestConfig.ReattachConfigCh`](https://github.com/hashicorp/go-plugin/blob/721087dad1e61cd41a19a30e5ae740dceb55061d/server.go#L121), passing it to the client. The problem is that the server and client are versioned, so the client config has a map of [`VersionedPlugins`](https://github.com/hashicorp/go-plugin/blob/721087dad1e61cd41a19a30e5ae740dceb55061d/client.go#L154) while [`Plugins`](https://github.com/hashicorp/go-plugin/blob/721087dad1e61cd41a19a30e5ae740dceb55061d/client.go#L149) is empty. When the client is created using the reattach config, [`Client.Start`](https://github.com/hashicorp/go-plugin/blob/721087dad1e61cd41a19a30e5ae740dceb55061d/client.go#L581) exits early by calling [`c.reattach()`](https://github.com/hashicorp/go-plugin/blob/721087dad1e61cd41a19a30e5ae740dceb55061d/client.go#L617), skipping the part where the [plugin version is determined](https://github.com/hashicorp/go-plugin/blob/721087dad1e61cd41a19a30e5ae740dceb55061d/client.go#L869-L880) 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](https://github.com/hashicorp/go-plugin/assets/8320753/81b94787-415d-405b-8226-30e64f5cf6bb)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.