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

fix: npe when killing plugin client #947

Merged
merged 1 commit into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func mockPlugin() {
mockey.Mock(modules.NewPlugin).To(func(key string) (*modules.Plugin, error) {
return &modules.Plugin{Module: &fakeModule{}}, nil
}).Build()
mockey.Mock((*modules.Plugin).KillPluginClient).Return().Build()
mockey.Mock((*modules.Plugin).KillPluginClient).Return(nil).Build()
}

func TestAppConfigurationGenerator_Generate_CustomNamespace(t *testing.T) {
Expand Down
9 changes: 6 additions & 3 deletions pkg/modules/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ var PluginMap = map[string]plugin.Plugin{
}

type Plugin struct {
// key represents the module key, it consists of two parts: moduleName@version. e.g. "kusionstack/mysql@v0.1"
// key represents the module key, it consists of two parts: moduleName@version. e.g. "kusionstack/mysql@v0.1.0"
key string
client *plugin.Client
// Module represents the real module impl
Expand Down Expand Up @@ -126,9 +126,12 @@ func newPluginClient(path string) *plugin.Client {
return client
}

func (p *Plugin) KillPluginClient() {
// fixme: if p.client is nil, it will panic
func (p *Plugin) KillPluginClient() error {
if p.client == nil {
return fmt.Errorf("plugin: %s client is nil", p.key)
}
p.client.Kill()
return nil
}

func PluginDir() (string, error) {
Expand Down
Loading