Repository navigation
Avoid a hang when Git is slow to provide us data - #3806
Merged
Merged
Conversation
When we are cloning or checking out a repo, the filter-process smudge filter sends the transfer queue data by calling the Add method. This method inserts items into the incoming channel, which is then processed by the collectBatches function. This function accepts items, downloads a batch worth, and splits the remainder into the next and pending queues, and then, if there are any items in either of these queues, goes around again. If there are no items, it exits the download queue. Unfortunately, this algorithm has a problem. If the filter-process portion is slow and does not provide us enough data, we can end up with both the next and pending queues empty, but the incoming channel still open, waiting for the filter-process end to send more data. In such a case, we stop downloading early and the process deadlocks since there's nobody to read from the channel. The solution, however, is simple: since we set the closing flag whenever the incoming channel is closed, we can check if that flag is set and only quit if it is. We know that if it is not, there's more data, and the other end of the channel is just being slow (perhaps because Git is processing other filters). Do this to avoid the deadlock and ensure that we terminate properly in all cases.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When we are cloning or checking out a repo, the filter-process smudge filter sends the transfer queue data by calling the Add method. This method inserts items into the incoming channel, which is then processed by the collectBatches function. This function accepts items, downloads a batch worth, and splits the remainder into the next and pending queues, and then, if there are any items in either of these queues, goes around again. If there are no items, it exits the download queue.
Unfortunately, this algorithm has a problem. If the filter-process portion is slow and does not provide us enough data, we can end up with both the next and pending queues empty, but the incoming channel still open, waiting for the filter-process end to send more data. In such a case, we stop downloading early and the process deadlocks since there's nobody to read from the channel.
The solution, however, is simple: since we set the closing flag whenever the incoming channel is closed, we can check if that flag is set and only quit if it is. We know that if it is not, there's more data, and the other end of the channel is just being slow (perhaps because Git is processing other filters). Do this to avoid the deadlock and ensure that we terminate properly in all cases.
Fixes #3801.
/cc @r0nw as reporter