Skip to content

fix(functions): clean up all orphaned local-run directories - #3989

Open
Elvand-Lie wants to merge 2 commits into
knative:mainfrom
Elvand-Lie:fix/cleanup-all-orphaned-job-dirs
Open

fix(functions): clean up all orphaned local-run directories#3989
Elvand-Lie wants to merge 2 commits into
knative:mainfrom
Elvand-Lie:fix/cleanup-all-orphaned-job-dirs

Conversation

@Elvand-Lie

@Elvand-Lie Elvand-Lie commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Changes

cleanupJobDirs() now keeps scanning .func/runs/ after removing an orphaned run directory, so a new Job cleans up every stale entry instead of only the first one. The regression test covers one active run directory, two stale directories, and the newly created Job.

Problem

cleanupJobDirs() returned directly from the directory loop after its first successful os.RemoveAll(...) call. If more than one stale .func/runs/<port> directory existed, the remaining entries were left behind and could still be reported as local function instances. Local invocation could then select a stale port even when a new function was available on another port.

Fix

The cleanup loop now continues after each successful removal and returns only when a removal fails. Active port directories are still preserved, files and non-integer directories are still ignored, and there are no public API or metadata changes.

Testing

The regression test creates one active run directory, two stale run directories, and one new Job. It verifies that both stale directories are removed, the active directory remains, and the new Job directory is created.

The exact submitted commit (beccbf4e8ba4fad6fc6b83b3d0742774a870e30b) passed the full workflow in the fork: https://github.com/Elvand-Lie/func/actions/runs/30923394939. All 23 applicable unit, integration, template, Podman, and runtime E2E jobs passed; the three release/publish jobs were skipped as expected.

Local static checks (gofmt, git diff --check, and make check-whitespace check-eof) also passed. Full Go tests could not run locally because the ARM64 environment could not retrieve the Go 1.26 toolchain, so the fork workflow supplied that validation.

Release Note

Fixed local run cleanup so all stale `.func/runs/<port>` directories are removed before registering a new Job.

Docs

NONE

Signed-off-by: Elvand-Lie <elvandlie@gmail.com>
@knative-prow knative-prow Bot added the kind/bug Bugs label Aug 4, 2026
@knative-prow
knative-prow Bot requested a review from dsimansk August 4, 2026 16:18
@knative-prow

knative-prow Bot commented Aug 4, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Elvand-Lie
Once this PR has been reviewed and has the lgtm label, please assign dsimansk for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knative-prow
knative-prow Bot requested a review from jrangelramos August 4, 2026 16:18
@knative-prow knative-prow Bot added the size/M 🤖 PR changes 30-99 lines, ignoring generated files. label Aug 4, 2026
@knative-prow

knative-prow Bot commented Aug 4, 2026

Copy link
Copy Markdown

Hi @Elvand-Lie. Thanks for your PR.

I'm waiting for a knative member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Tip

We noticed you've done this a few times! Consider joining the org to skip this step and gain /lgtm and other bot rights. We recommend asking approvers on your previous PRs to sponsor you.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@knative-prow knative-prow Bot added the needs-ok-to-test 🤖 Needs an org member to approve testing label Aug 4, 2026
@knative-prow

knative-prow Bot commented Aug 4, 2026

Copy link
Copy Markdown

@Elvand-Lie: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

Details

In response to this:

/retest-required

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Signed-off-by: Elvand-Lie <elvandlie@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Bugs needs-ok-to-test 🤖 Needs an org member to approve testing size/M 🤖 PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant