Skip to content

Commit

Permalink
drivers: update ordering of events in StartTask to fix executor leak
Browse files Browse the repository at this point in the history
If an error occurs before a task is started, but after this executor
process is created, the executor must be explicity stopped.  This change
updates the logic in StartTask so launching the task happens immediately
after creating the executor.
  • Loading branch information
mismithhisler committed Nov 19, 2024
1 parent 6be9a50 commit c772de5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
16 changes: 9 additions & 7 deletions drivers/exec/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -492,13 +492,6 @@ func (d *Driver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *drive
Compute: d.compute,
}

exec, pluginClient, err := executor.CreateExecutor(
d.logger.With("task_name", handle.Config.Name, "alloc_id", handle.Config.AllocID),
d.nomadConfig, executorConfig)
if err != nil {
return nil, nil, fmt.Errorf("failed to create executor: %v", err)
}

user := cfg.User
if cfg.DNS != nil {
dnsMount, err := resolvconf.GenerateDNSMount(cfg.TaskDir().Dir, cfg.DNS)
Expand All @@ -516,6 +509,15 @@ func (d *Driver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *drive
}
d.logger.Debug("task capabilities", "capabilities", caps)

// If any error scenarios occur in StartTask and after creating the executor process,
// the executor process must be killed.
exec, pluginClient, err := executor.CreateExecutor(
d.logger.With("task_name", handle.Config.Name, "alloc_id", handle.Config.AllocID),
d.nomadConfig, executorConfig)
if err != nil {
return nil, nil, fmt.Errorf("failed to create executor: %v", err)
}

execCmd := &executor.ExecCommand{
Cmd: driverConfig.Command,
Args: driverConfig.Args,
Expand Down
16 changes: 9 additions & 7 deletions drivers/java/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,13 +467,6 @@ func (d *Driver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *drive
Compute: d.nomadConfig.Topology.Compute(),
}

exec, pluginClient, err := executor.CreateExecutor(
d.logger.With("task_name", handle.Config.Name, "alloc_id", handle.Config.AllocID),
d.nomadConfig, executorConfig)
if err != nil {
return nil, nil, fmt.Errorf("failed to create executor: %v", err)
}

user := cfg.User
if user == "" {
user = "nobody"
Expand All @@ -495,6 +488,15 @@ func (d *Driver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *drive
}
d.logger.Debug("task capabilities", "capabilities", caps)

// If any error scenarios occur in StartTask and after creating the executor process,
// the executor process must be killed.
exec, pluginClient, err := executor.CreateExecutor(
d.logger.With("task_name", handle.Config.Name, "alloc_id", handle.Config.AllocID),
d.nomadConfig, executorConfig)
if err != nil {
return nil, nil, fmt.Errorf("failed to create executor: %v", err)
}

execCmd := &executor.ExecCommand{
Cmd: absPath,
Args: args,
Expand Down

0 comments on commit c772de5

Please sign in to comment.