Skip to content

Commit

Permalink
Configure plugin start timeout for go-plugin.Client (turbot#4477)
Browse files Browse the repository at this point in the history
  • Loading branch information
nmische committed Jan 25, 2025
1 parent 65cf412 commit c1a165f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 2 additions & 0 deletions pkg/pluginmanager/lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"log"
"os/exec"
"syscall"
"time"

"github.com/hashicorp/go-hclog"
"github.com/hashicorp/go-plugin"
Expand Down Expand Up @@ -64,6 +65,7 @@ func start(steampipeExecutablePath string) (*State, error) {
Cmd: pluginManagerCmd,
AllowedProtocols: []plugin.Protocol{plugin.ProtocolGRPC},
Logger: logger,
StartTimeout: 3 * time.Minute, //TODO: macke this configurable
})

if _, err := client.Start(); err != nil {
Expand Down
16 changes: 15 additions & 1 deletion pkg/pluginmanager_service/plugin_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -501,11 +501,25 @@ func (m *PluginManager) startPluginProcess(pluginInstance string, connectionConf

cmd := exec.Command(pluginPath)
m.setPluginMaxMemory(pluginConfig, cmd)
pluginStartTimeoutSecs := pluginConfig.GetStartTimeout()
if pluginStartTimeoutSecs == 0 {
if viper.IsSet(pconstants.ArgPluginStartTimeout) {
pluginStartTimeoutSecs = viper.GetInt64(pconstants.ArgPluginStartTimeout)
}
}
if pluginStartTimeoutSecs == 0 {
// if we don't have any timeout set use 30 seconds
pluginStartTimeoutSecs = int64(30)
}
pluginStartTimeoutDuration := time.Duration(pluginStartTimeoutSecs) * time.Second
log.Printf("[TRACE] %s pluginStartTimeoutDuration: %s", pluginPath, pluginStartTimeoutDuration)

client := goplugin.NewClient(&goplugin.ClientConfig{
HandshakeConfig: sdkshared.Handshake,
Plugins: pluginMap,
Cmd: cmd,
AllowedProtocols: []goplugin.Protocol{goplugin.ProtocolGRPC},
StartTimeout: pluginStartTimeoutDuration,

// pass our logger to the plugin client to ensure plugin logs end up in logfile
Logger: m.logger,
Expand Down Expand Up @@ -678,7 +692,7 @@ func (m *PluginManager) waitForPluginLoad(p *runningPlugin, req *pb.GetRequest)
}
pluginStartTimeoutSecs := pluginConfig.GetStartTimeout()
if pluginStartTimeoutSecs == 0 {
if viper.IsSet(pconstants.ArgMemoryMaxMbPlugin) {
if viper.IsSet(pconstants.ArgPluginStartTimeout) {
pluginStartTimeoutSecs = viper.GetInt64(pconstants.ArgPluginStartTimeout)
}
}
Expand Down

0 comments on commit c1a165f

Please sign in to comment.