Skip to content

Commit

Permalink
backport of commit 4e2d967 (#24577)
Browse files Browse the repository at this point in the history
Co-authored-by: Michael Smithhisler <[email protected]>
  • Loading branch information
1 parent 7dd0b2c commit 5eb85b7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .changelog/24538.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
executor: validate executor on reattach to avoid possibility of killing non-Nomad processes
```
15 changes: 13 additions & 2 deletions drivers/shared/executor/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ func CreateExecutor(
return newExecutorClient(config, logger)
}

// ReattachToExecutor launches a plugin with a given plugin config
// ReattachToExecutor launches a plugin with a given plugin config and validates it can call the executor.
// Note: On Windows, go-plugin listens on a localhost port. It is possible on a reboot that another process
// is listening on that port, and a process is running with the previous executors PID, leading the Nomad
// TaskRunner to kill the PID after it errors calling the Wait RPC. So, fail early via the Version RPC if
// we detect the listener isn't actually an Executor.
func ReattachToExecutor(reattachConfig *plugin.ReattachConfig, logger hclog.Logger, compute cpustats.Compute) (Executor, *plugin.Client, error) {
config := &plugin.ClientConfig{
HandshakeConfig: base.Handshake,
Expand All @@ -84,7 +88,14 @@ func ReattachToExecutor(reattachConfig *plugin.ReattachConfig, logger hclog.Logg
AllowedProtocols: []plugin.Protocol{plugin.ProtocolGRPC},
Logger: logger.Named("executor"),
}
return newExecutorClient(config, logger)
exec, pluginClient, err := newExecutorClient(config, logger)
if err != nil {
return nil, nil, err
}
if _, err := exec.Version(); err != nil {
return nil, nil, err
}
return exec, pluginClient, nil
}

func newExecutorClient(config *plugin.ClientConfig, logger hclog.Logger) (Executor, *plugin.Client, error) {
Expand Down

0 comments on commit 5eb85b7

Please sign in to comment.