Skip to content

gitpipe: Close channel only after queue cleanup

CatfileInfo returns an iterator, the Next() function of the iterator returns false when the iterator has no more entries. The test TestCatfileInfo/spawning_two_pipes_fails creates such an iterator with a objectInfoReader queue.

When the Next() function returns a false, it uses the queue to create another CatfileInfo iterator and uses it. There is race condition here between the cleanup of the queue by the first iterator and the usage of the same queue by the second iterator.

To fix this race, we ensure that the iterators internal channel is only closed after the queue cleanup is called. This ensures that if required, the cleanup would be performed before Next() would ever return a false value. This avoids the race condition.

While here, we also ensure that the test also checks for Err() function which is recommended whenever the Next() function returns a false value. This has not connected to the race condition fixed in this patch.

Closes #5102 (closed)

Edited by Karthik Nayak

Merge request reports