Skip to content

file.managed: list source eagerly calls cp.list_master before checking HTTP sources #69804

Closed as not planned

Description

@Prajwalprakash3722

Description

When file.managed uses a list of sources, file.source_list calls cp.list_master and cp.list_master_dirs before iterating through the list — even if the first source is HTTP and would resolve immediately.

https://github.com/saltstack/salt/blob/master/salt/modules/file.py#L4730-L4740

mfiles = [(f, saltenv) for f in __salt__["cp.list_master"](saltenv)]
mdirs = [(d, saltenv) for d in __salt__["cp.list_master_dirs"](saltenv)]

This means every state with a list source pays the cost of a full fileserver scan upfront, regardless of source order.

Reproduce

/tmp/test_file:
  file.managed:
    - source:
      - https://example.com/myfile
      - salt://myfile
    - skip_verify: True
time salt-call state.apply test

With a large fileserver (10k+ files), this is noticeably slow or times out — even though the HTTP source would succeed in milliseconds.

Expected

Salt should check sources in order and only call cp.list_master if it actually reaches a salt:// entry.

Suggested Fix

Lazy-evaluate — only fetch the file listing when a salt:// source is reached:

_cache = {}

def _get_mfiles(env):
    if env not in _cache:
        _cache[env] = set(__salt__["cp.list_master"](env))
    return _cache[env]

Replace (path, senv) in mfiles with path in _get_mfiles(senv).

Also changes lookup from O(n) list scan to O(1) set membership.

Versions

All versions affected. Confirmed on 3006.x, code unchanged in master.

Activity

  1. Prajwalprakash3722 commented on Jul 14, 2026

    @Prajwalprakash3722
    Author
  2. added a commit that references this issue on Jul 18, 2026
    836643e
  3. added
    severity-low
    bug
    on Oct 21, 2026
  4. dwoz commented on Oct 23, 2026

    @dwoz
    Contributor

    Closing as part of a backlog cleanup — this issue was filed without a Salt versions-report, so there's no explicit version attached to compare against.

    If you (or anyone else) can still reproduce this on 3008.3 or later, please comment with:

    • A fresh reproduction
    • The output of salt --versions-report

    and the issue will be reopened. The original reporter can also reopen directly.

  5. added a commit that references this issue on Nov 24, 2026
    09451e2
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

    bugseverity-low

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions