Skip to content

catfile: Make process cancellation synchronous to fix test race

The catfile cache is using Goroutines to clean up processes. This is not deterministic and thus frequently causes our tests to flake when we lose one of the races caused by this. Furthermore, the asynchronicity makes the code quite hard to understand.

Refactor the code to use synchronous cancellation. Instead of waiting for the context to get cancelled, it is now the caller that is responsible for killing the process. The caller transparently either gets a cancellation function that

- kills the process directly in case it is an uncachable process.

- or returns the process to the cache in case it is a cachable
  process.

This significantly simplifies the code and also makes it deterministic, which fixes the flaky tests we have observed. Furthermore, this also allows us to get rid of one more Goroutine per cached catfile process.

Note that this allows us to get rid of the signalling logic we had in place previous to this change: there is no need to wait for processes to return to the cache in our tests anymore because this is now guaranteed after the cancellation function was called.

Edited by Patrick Steinhardt

Merge request reports