gitforge/modules/process
Mathieu Fenniak d4e2bf7396 fix: intermittent test failure in process cancellation (#13293)
Test failure: https://codeberg.org/forgejo/forgejo/actions/runs/174007/jobs/2/attempt/1   Have only observed once and can't reproduce locally, but likely caused by #13263 / #13289.

```
--- FAIL: TestGetDiffPreview (0.20s)
    --- FAIL: TestGetDiffPreview/empty_branch,_same_results (0.02s)
        diff_test.go:132:
            	Error Trace:	/workspace/forgejo/forgejo/services/repository/files/diff_test.go:132
            	Error:      	Received unexpected error:
            	            	unable to run diff-index pipeline in temporary repo: exec: canceling Cmd: invalid argument
            	Test:       	TestGetDiffPreview/empty_branch,_same_results
FAIL
```

pidfd_open is [documented](https://www.man7.org/linux/man-pages/man2/pidfd_open.2.html) to return the EINVAL (invalid argument) error if the pid is not valid, which could happen if the process terminates itself before Forgejo sends `SIGTERM`.  This PR adds a check for that error and stops `Cancel`, with a minor refactor to avoid code duplication.

### Tests for Go changes

- I added test coverage for Go changes...
  - [x] in their respective `*_test.go` for unit tests.
  - [x] in the `tests/integration` directory if it involves interactions with a live Forgejo server.
- I ran...
  - [x] `make pr-go` before pushing

### Documentation

- [ ] I created a pull request [to the documentation](https://codeberg.org/forgejo/docs) to explain to Forgejo users how to use this change.
- [x] I did not document these changes and I do not expect someone else to do it.

### Release notes

- [ ] This change will be noticed by a Forgejo user or admin (feature, bug fix, performance, etc.). I suggest to include a release note for this change.
- [x] This change is not visible to a Forgejo user or admin (refactor, dependency upgrade, etc.). I think there is no need to add a release note for this change.

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/13293
Reviewed-by: Andreas Ahlenstorf <aahlenst@noreply.codeberg.org>
2026-07-04 04:49:36 +02:00
..
context.go
error.go
graceful_cancel.go fix: intermittent test failure in process cancellation (#13293) 2026-07-04 04:49:36 +02:00
graceful_cancel_linux.go fix: intermittent test failure in process cancellation (#13293) 2026-07-04 04:49:36 +02:00
graceful_cancel_unix.go fix: restore Forgejo's capability to build on non-Linux UNIX platforms (#13289) 2026-07-02 23:04:07 +02:00
manager.go fix: restore Forgejo's capability to build on non-Linux UNIX platforms (#13289) 2026-07-02 23:04:07 +02:00
manager_exec.go
manager_stacktraces.go
manager_stacktraces_test.go
manager_test.go
manager_unix.go fix: restore Forgejo's capability to build on non-Linux UNIX platforms (#13289) 2026-07-02 23:04:07 +02:00
process.go