Prevent catfile error return resource leak
Fixes #1824 (closed)
We spawn git cat-file
processes in pairs: one --batch-check
for metadata lookup, and one --batch
for full object lookup. We had a bug in the spawn routine where if we fail in the middle, after having spawned just one of the two, we would leak the first process. Prior to the cat-file cache this bug was masked by the fact that gRPC request cancelation would clean up the leaked process for us anyway. However, with the cat-file cache, we have contexts that last much longer; in this particular case we were also leaking contexts that never got canceled.
This MR addresses the problem by using a temporary context scoped to the spawn function which gets canceled on all error return paths. In order to test this, we add an error injection mechanism.