Skip to content

exec -internal-pid-file cannot be used reliably #11851

@stepancheg

Description

@stepancheg

Description

runsc exec has -internal-pid-file flag.

According to this code, this file may not be written atomically:

gvisor/runsc/cmd/exec.go

Lines 291 to 296 in 6308502

// File appeared, check whether pid is fully written.
pid, err := strconv.Atoi(string(pidb))
if err != nil {
return false, nil
}
return pid == cmd.Process.Pid, nil

(I think it is generally written atomically, and I struggle to find examples when it is not, but Linux does not provide such guarantees, and gVisor itself does not assume it is written atomically).

So practically, when using runsc exec without -detach flag (that executes code above), it is not possible to reliably know process id when using -internal-pid-file.

Is this feature related to a specific bug?

No response

Do you have a specific solution in mind?

I have two options in mind

  • write trailing newline to -internal-pid-file file, so a user can assume that the file is fully written when trailing newline is present. That looks like the best option, if backwards compatibility is not an issue
  • add a new flag like -exec-info-file that would contain a JSON with process ids. Overengineering for such simple problem
  • do nothing because the problem is improbable

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions