Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libgit2: ensure context timeout cancels transfer #477

Merged
merged 4 commits into from
Nov 4, 2021
Merged

Conversation

hiddeco
Copy link
Member

@hiddeco hiddeco commented Oct 28, 2021

libgit2 seems to assume that a transport will eventually tell by
itself that it has timed out. This also means that at present any
timeout configuration does not seem have an effect. It will continue
to transfer until the remote (or something else) tells it is no
longer transferring.

This commit adds libgit2 remote callbacks SidebandProgressCallback,
TransferProgressCallback and PushTransferProgressCallback to
signal libgit2 to stop the operations based on the context and the
operation status.

Refer git2go/remote.go for a list of supported remote callbacks.

@hiddeco hiddeco changed the title libgit2: ensure Timeout cancels transfer libgit2: ensure context timeout cancels transfer Oct 28, 2021
@hiddeco hiddeco force-pushed the libgit2-timeout branch 2 times, most recently from 0093d58 to 0b94450 Compare October 28, 2021 19:58
@hiddeco hiddeco added the area/git Git related issues and pull requests label Oct 28, 2021
hiddeco and others added 3 commits November 2, 2021 02:55
With the information from the refactor still fresh in mind, I continue
to find new paths now I mentally tamed the git2go beast.

`libgit2` seems to assume that a transport will eventually tell by
itself that it has timed out. This also means that at present any
timeout configuration does not seem have an effect. It will continue
to transfer until the remote (or _something_ else) tells it is no
longer transfering.

This commit introduces a simple check (without tests) which was used
to confirm the theory in combination with the tests in
`pkg/git/strategy` (by setting it to a very low timeout and observing
it fail).

A future iteration should probably take the data given to the callback
into account to ensure it doesn't error out if the given data[1]
reports it has successfully received all objects. Another candidate
for this check may be `CompletionCallback`, but one should study the
C code (and likely some Go code as well) before this.

In addition, to ensure the same timeout is taken into account for push
operations, `PushTransferProgressCallback` may require a likewise
helper.

[1]: https://github.com/libgit2/git2go/blob/main/remote.go#L50-L58

Signed-off-by: Hidde Beydals <hello@hidde.co>
In transferProgressCallback(), if the received objects is equal to the
total objects, return early with OK.

Signed-off-by: Sunny <darkowlzz@protonmail.com>
Add SidebandProgressCallback to be able to cancel the network operation
before any transfer operation.
Add PushTransferProgressCallback to be able to cancel the push transfer
operation.

Signed-off-by: Sunny <darkowlzz@protonmail.com>
@darkowlzz
Copy link
Contributor

darkowlzz commented Nov 1, 2021

Added SidebandProgressCallback/TransportMessageCallback and PushTransferProgressCallback to be able to cancel the network operation before any transfer and cancel push transfer operation respectively.

CompletionCallback is for notifying the completion of download and indexing, but it's currently unused.

Performed some manual testing of SidebandProgressCallback to cancel the network operation by returning error, it causes checkout tests to fail, similar to the failure caused by TransferProgressCallback error, but before any transfer initiation.

- Adds tests for the libgit2 remote callbacks
- Adds tests for CheckoutStrategyForImplementation with context timeout
  and verify timeout is respected by both the git implementations.

Signed-off-by: Sunny <darkowlzz@protonmail.com>
@darkowlzz darkowlzz marked this pull request as ready for review November 3, 2021 21:21
Copy link
Member Author

@hiddeco hiddeco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can not review my own PR, but this looks good to me. Thanks a lot for taking over and getting to the bottom of it @darkowlzz 🌻

Copy link
Member

@stefanprodan stefanprodan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Thanks @hiddeco and @darkowlzz 🏅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/git Git related issues and pull requests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants