Skip to content

Europa: engine.#Exec: attach stdin, stdout, stderr #1222

Closed

Description

@shykes

Expand the Engine API to give developers control over the standard streams (stdin, stdout, stderr) of the commands they’re executing.

This was part in the original Europa spec, but was temporarily removed to resolve outstanding design issues:

  • How to handle multiple writers? Are they forbidden? Do they randomly share the stream? Undefined behavior? Is the full stream multiplexed to each reader?
  • How to avoid deadlocks? Unix-style pipes require concurrent execution. But the original spec leads to sequential execution because the stdout/stdin link is considered to be a dependency. This requires further design discussion
  • How can the streams be used other than to chain commands? Could they eventually be exposed to the client as inputs or outputs?

For reference, here is the original spec:

package engine

#Stream: {
  _stream: ID: string
}

#Exec: {
  // […]

   // Optionally attach to command standard input stream
    stdin?: #Stream

   // Optionally attach to command standard output stream
    stdout?: #Stream

   // Optionally attach to command standard error stream
    stderr?: #Stream
}

Activity

  1. self-assigned this
    on Dec 14, 2021
  2. added this to the milestone on Dec 14, 2021
  3. aluzzardi commented on Dec 15, 2021

    @aluzzardi
    Contributor

    I think this is a risky business. Dagger execution is non-linear and cached, unlike cue/cmd and shell scripts.

    Users declare things that should happen -- IMHO dealing with streams is in the realm of imperative scripting and doesn't match the dagger execution model.

    Beside the design issues listed above:

    • What happens with cached tasks?

    a reads from b's stdout. Now b is cached. What happens?

    Perhaps a gets an EOF immediately. But this means that caching is no longer just caching, it affects the outcome of computation. Which I think would make dagger unpredictable (e.g. running dagger up twice in a row might yield a different result, depending on individual task caching).

    • stdout / stderr as data

    Maybe we can have the runtime helper write stdout/stderr to the filesystem. That way, the runtime could ReadFile at the end of Exec and get consistent results, whether the task was executed or cached. (similar to cue/cmd's stdout: string design)

    • stdin is a vertex input outside of buildkit

    stdin is even more tricky. Since we'd have to rely on a runtime helper, stdin is not part of the LLB vertex.

    Example (pseudo-code):

    foo: exec.#Command & {
      stdin: "foo"
      args: ["cat"]
    }
    • Run once. foo.stdout is foo.
    • Now change foo.stdin to bar.
    • Run again. foo.stdout is still foo.

    Since stdin is not part of the BuildKit vertex, changing it does not affect cache status.

  4. shykes commented on Jan 4, 2022

    @shykes
    ContributorAuthor

    Design issues seem insurmountable, and nobody actually expressed a need for it yet. Closing for now. Resurrect if this becomes needed again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions