From 4e2d9675e7308db3557a273230a1bc5d19f53cce Mon Sep 17 00:00:00 2001 From: Michael Smithhisler Date: Mon, 2 Dec 2024 09:56:00 -0500 Subject: [PATCH] executor: fail early on reattach if listener is not executor (#24538) --- .changelog/24538.txt | 3 +++ drivers/shared/executor/utils.go | 15 +++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 .changelog/24538.txt diff --git a/.changelog/24538.txt b/.changelog/24538.txt new file mode 100644 index 00000000000..4f5ac9b376a --- /dev/null +++ b/.changelog/24538.txt @@ -0,0 +1,3 @@ +```release-note:bug +executor: validate executor on reattach to avoid possibility of killing non-Nomad processes +``` diff --git a/drivers/shared/executor/utils.go b/drivers/shared/executor/utils.go index b74c5372823..fa6484d5f46 100644 --- a/drivers/shared/executor/utils.go +++ b/drivers/shared/executor/utils.go @@ -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, @@ -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) {