fix: remove LXC backend leftovers when the job completes #1054

Merged
earl-warren merged 1 commit from earl-warren/runner:wip-cleanup into main 2025-10-03 16:14:09 +00:00
Contributor
  • remove the root of the LXC container after destroying it, with sudo as it may contain files owned by root while the runner id is not root
  • os.RemoveAll only for native host runs, it is no longer needed for the LXC backend
  • remove the CleanUp function that is an indirection with no use

Resolves forgejo/runner#442

When running the test from a non-root user and without this fix, it fails as follow:

go test -v -count=1 -run='TestRunnerLXC' ./internal/app/run
=== RUN   TestRunnerLXC
...
time="2025-10-03T15:05:12+02:00" level=debug msg=stopHostEnvironment
time="2025-10-03T15:05:13+02:00" level=debug msg="HostEnvironment.Remove /tmp/TestRunnerLXC1841090130/001/d29c1256e2912892/hostexecutor"
time="2025-10-03T15:05:13+02:00" level=error msg="Error while stop job container FORGEJO-ACTIONS-TASK-0_WORKFLOW-3ede81fbc69d42e6db70bef5820490fc3e7dc4d9dcbfb64981f2d00f08a30d6e_JOB-job: unlinkat /tmp/TestRunnerLXC1841090130/001/d29c1256e2912892/hostexecutor/some/directory/owned/by/root: permission denied"
=== NAME  TestRunnerLXC
    runner_test.go:469: 
        	Error Trace:	/home/earl-warren/software/runner/internal/app/run/runner_test.go:469
        	            				/home/earl-warren/software/runner/internal/app/run/runner_test.go:496
        	Error:      	Received unexpected error:
        	            	Error occurred running finally: unlinkat /tmp/TestRunnerLXC1841090130/001/d29c1256e2912892/hostexecutor/some/directory/owned/by/root: permission denied (original error: <nil>)
        	Test:       	TestRunnerLXC
        	Messages:   	OK
=== NAME  TestRunnerLXC/OK
    testing.go:1679: test executed panic(nil) or runtime.Goexit: subtest may have called FailNow on a parent test
=== NAME  TestRunnerLXC
    testing.go:1267: TempDir RemoveAll cleanup: unlinkat /tmp/TestRunnerLXC1841090130/001/d29c1256e2912892/hostexecutor/some/directory/owned/by/root: permission denied
--- FAIL: TestRunnerLXC (6.84s)
    --- FAIL: TestRunnerLXC/OK (6.84s)
FAIL
FAIL	code.forgejo.org/forgejo/runner/v11/internal/app/run	6.847s
FAIL
  • bug fixes
    • PR: fix: remove LXC backend leftovers when the job completes
- remove the root of the LXC container after destroying it, with sudo as it may contain files owned by root while the runner id is not root - os.RemoveAll only for native host runs, it is no longer needed for the LXC backend - remove the CleanUp function that is an indirection with no use Resolves forgejo/runner#442 When running the test from a non-root user and without this fix, it fails as follow: ``` go test -v -count=1 -run='TestRunnerLXC' ./internal/app/run === RUN TestRunnerLXC ... time="2025-10-03T15:05:12+02:00" level=debug msg=stopHostEnvironment time="2025-10-03T15:05:13+02:00" level=debug msg="HostEnvironment.Remove /tmp/TestRunnerLXC1841090130/001/d29c1256e2912892/hostexecutor" time="2025-10-03T15:05:13+02:00" level=error msg="Error while stop job container FORGEJO-ACTIONS-TASK-0_WORKFLOW-3ede81fbc69d42e6db70bef5820490fc3e7dc4d9dcbfb64981f2d00f08a30d6e_JOB-job: unlinkat /tmp/TestRunnerLXC1841090130/001/d29c1256e2912892/hostexecutor/some/directory/owned/by/root: permission denied" === NAME TestRunnerLXC runner_test.go:469: Error Trace: /home/earl-warren/software/runner/internal/app/run/runner_test.go:469 /home/earl-warren/software/runner/internal/app/run/runner_test.go:496 Error: Received unexpected error: Error occurred running finally: unlinkat /tmp/TestRunnerLXC1841090130/001/d29c1256e2912892/hostexecutor/some/directory/owned/by/root: permission denied (original error: <nil>) Test: TestRunnerLXC Messages: OK === NAME TestRunnerLXC/OK testing.go:1679: test executed panic(nil) or runtime.Goexit: subtest may have called FailNow on a parent test === NAME TestRunnerLXC testing.go:1267: TempDir RemoveAll cleanup: unlinkat /tmp/TestRunnerLXC1841090130/001/d29c1256e2912892/hostexecutor/some/directory/owned/by/root: permission denied --- FAIL: TestRunnerLXC (6.84s) --- FAIL: TestRunnerLXC/OK (6.84s) FAIL FAIL code.forgejo.org/forgejo/runner/v11/internal/app/run 6.847s FAIL ``` <!--start release-notes-assistant--> <!--URL:https://code.forgejo.org/forgejo/runner--> - bug fixes - [PR](https://code.forgejo.org/forgejo/runner/pulls/1054): <!--number 1054 --><!--line 0 --><!--description Zml4OiByZW1vdmUgTFhDIGJhY2tlbmQgbGVmdG92ZXJzIHdoZW4gdGhlIGpvYiBjb21wbGV0ZXM=-->fix: remove LXC backend leftovers when the job completes<!--description--> <!--end release-notes-assistant-->
earl-warren force-pushed wip-cleanup from 3577b08471
All checks were successful
cascade / forgejo (pull_request_target) Has been skipped
cascade / debug (pull_request_target) Has been skipped
cascade / end-to-end (pull_request_target) Has been skipped
issue-labels / release-notes (pull_request_target) Successful in 9s
checks / validate pre-commit-hooks file (pull_request) Successful in 36s
checks / validate mocks (pull_request) Successful in 51s
checks / build and test (pull_request) Successful in 2m35s
checks / runner exec tests (pull_request) Successful in 21s
checks / runner integration tests (pull_request) Successful in 4m13s
checks / integration tests (pull_request) Successful in 10m57s
to b4eb780122
All checks were successful
checks / validate pre-commit-hooks file (pull_request) Successful in 50s
checks / validate mocks (pull_request) Successful in 1m19s
checks / build and test (pull_request) Successful in 1m39s
checks / runner exec tests (pull_request) Successful in 39s
checks / runner integration tests (pull_request) Successful in 6m23s
checks / integration tests (pull_request) Successful in 13m35s
issue-labels / release-notes (pull_request_target) Successful in 5s
cascade / debug (pull_request_target) Has been skipped
cascade / end-to-end (pull_request_target) Successful in 5s
cascade / forgejo (pull_request_target) Successful in 2m6s
2025-10-03 13:00:15 +00:00
Compare
earl-warren changed title from WIP: fix: cleanup hostexecutor directory to WIP: fix: remove LXC backend leftovers when the job completes 2025-10-03 13:20:28 +00:00
Contributor

cascading-pr updated at actions/setup-forgejo#703

cascading-pr updated at https://code.forgejo.org/actions/setup-forgejo/pulls/703
earl-warren changed title from WIP: fix: remove LXC backend leftovers when the job completes to fix: remove LXC backend leftovers when the job completes 2025-10-03 15:00:20 +00:00
mfenniak approved these changes 2025-10-03 15:34:29 +00:00
mfenniak left a comment

Looks good to me. I pulled down main, reproduced the issue, and then pulled the branch and ran through some tests with LXC & a host executor and had no cleanup errors.

The only leftovers in ~/.cache/act were from remote uses (eg. uses: actions/checkout@v3), which I imagine are expected to remain around for cache re-use?

Looks good to me. I pulled down main, reproduced the issue, and then pulled the branch and ran through some tests with LXC & a host executor and had no cleanup errors. The only leftovers in `~/.cache/act` were from remote `uses` (eg. `uses: actions/checkout@v3`), which I imagine are expected to remain around for cache re-use?
Author
Contributor

@mfenniak wrote in #1054 (comment):

The only leftovers in ~/.cache/act were from remote uses (eg. uses: actions/checkout@v3), which I imagine are expected to remain around for cache re-use?

Yes. It would be quite problematic to re-clone them every time 😁

@mfenniak wrote in https://code.forgejo.org/forgejo/runner/pulls/1054#issuecomment-62236: > The only leftovers in `~/.cache/act` were from remote `uses` (eg. `uses: actions/checkout@v3`), which I imagine are expected to remain around for cache re-use? Yes. It would be quite problematic to re-clone them every time 😁
earl-warren deleted branch wip-cleanup 2025-10-03 16:14:10 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No assignees
3 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
forgejo/runner!1054
No description provided.