Skip to content

bug: --concurrency silently accepts negative and zero values #2399

Done

Description

@TerryHowe

Description

--concurrency accepts any integer. No command checks the value, so a negative level is accepted silently and the command exits 0:

$ oras push --oci-layout /tmp/layout:test --concurrency -3 f.txt:application/octet-stream
Pushed [oci-layout] /tmp/layout:test
$ echo $?
0

What a non-positive level does depends on the code path:

  • The oras-go copy/tag paths (push, pull, cp, tag, attach, backup, restore, manifest push) reset a limit <= 0 to oras-go's default. The user's value is ignored without a warning.
  • internal/graph.FindPredecessors treats a non-positive limit as unbounded (errgroup semantics).

Neither result is what someone who typed a negative number meant. 0 is also not a reliable "no limit".

For comparison, oras discover --depth -1 already fails with depth value should be at least 1.

Expected behavior

A --concurrency value below 1 fails with a clear error before the command runs.

Suggested fix

Add a shared option.Concurrency that registers the flag and validates >= 1 in its Parse, and use it in every command that has --concurrency. Don't validate in the root command's PersistentPreRunE, because a subcommand that defines its own PersistentPreRunE would skip that check without anyone noticing.

This also covers the flag-consistency item in #2280: defaults are currently 3 (cp, pull, backup) or 5 (push, attach, restore, tag, manifest push).

Related

Evaluation

Decision needed: what about 0?

test/e2e/suite/command/cp.go runs oras cp -r --concurrency 0 in two tests (one titled "without concurrency limitation", added in #1122). On the cp -r referrer path, 0 currently means "no limit" in internal/graph. Rejecting values below 1, as proposed above, breaks that tested behavior and any scripts that pass 0. Options:

  • Reject < 1 everywhere (recommended). Consistent with discover --depth, and 0 already behaves differently across commands. Update the two cp e2e tests and note the change in the release notes.
  • Reject only < 0, and document a single meaning for 0.

Feasibility

Every affected command already calls option.Parse(cmd, &opts) in its PreRunE, and option.Parse (cmd/oras/internal/option/parser.go) calls Parse on every embedded field that implements FlagParser. Embedding a new option.Concurrency in each command's options gets validation with no extra wiring. Defaults differ per command (3 or 5), so the option needs a per-command default. Unifying the defaults (#2280) changes behavior and is better done in a separate PR.

Effort: small to medium. The check is trivial, but it touches 8 commands plus tests.

Suggested approach

  1. Add cmd/oras/internal/option/concurrency.go with:
    • ApplyFlags, which registers --concurrency with the command's default.
    • Parse, which fails with concurrency value should be at least 1 (same wording as discover).
  2. Replace the concurrency int field and the IntVarP registration in attach, backup, cp, pull, push, restore, tag, and manifest push. Keep today's defaults.
  3. As defense in depth, change internal/graph/graph.go FindPredecessors from if opts.Concurrency != 0 to > 0, so a negative limit can never mean unbounded.
  4. Tests:
    • A table-driven unit test for Concurrency.Parse (-1, 0, 1, default).
    • e2e error cases for the commands.
    • Change the two cp e2e tests to use a positive value.

Related code

  • Flag registrations: cmd/oras/root/{push,pull,cp,attach,tag,backup,restore}.go, cmd/oras/root/manifest/push.go
  • cmd/oras/internal/option/terminal.go: model for the ApplyFlags/Parse pattern
  • cmd/oras/root/discover.go: the existing --depth check
  • internal/graph/graph.go: FindPredecessors limit handling
  • test/e2e/suite/command/cp.go: the --concurrency 0 tests

The design is fully specified, so this is a good candidate for an outside contributor once the 0 question is settled.

Activity

  1. added
    bug
    on Nov 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions