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

executor: fail early on reattach if listener is not executor #24538

Merged
merged 3 commits into from
Dec 2, 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
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 {
mismithhisler marked this conversation as resolved.
Show resolved Hide resolved
return nil, nil, err
}
return exec, pluginClient, nil
}

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