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

plumbing: wire up contexts for Transport.AdvertisedReferences #246

Merged
merged 2 commits into from Mar 26, 2021

Conversation

asuffield
Copy link
Contributor

This is primarily for the sake of the http transport, which otherwise makes its first call without a context, causing context timeouts to not work if the remote is unresponsive.

Fixed up several tests which were getting this wrong. I am particularly fond of the ones which canceled the context and then proceeded to test that the function worked after being canceled.

The AdvertisedReferences function can be removed after this change, but this is technically breaking the API, since library users could call it, so it should really be deferred to v6.

@asuffield
Copy link
Contributor Author

Failed checks are a flaky test (network access from the test to the internet) and fractional coverage decrease from the shifting error paths, which I'm inclined to ignore.

@sevki
Copy link

sevki commented Jan 19, 2021

Perhaps someone should disable them all together

#51

@@ -1032,7 +1032,7 @@ func (r *Remote) List(o *ListOptions) (rfs []*plumbing.Reference, err error) {

defer ioutil.CheckClose(s, &err)

ar, err := s.AdvertisedReferences()
ar, err := s.AdvertisedReferencesContext(context.TODO())
Copy link
Contributor

@xiujuan95 xiujuan95 Mar 11, 2021

Choose a reason for hiding this comment

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

Hi, I was using go-git package to do git ls-remote check. But I found this command doesn't have a timeout configuration. I saw you were doing this action. That would be nice!

But why do you pass context.TODO() to it? As far as I know, context.TODO() ia an empty context. This means, git ls-remote also doesn't have timeout. Could you explain it for me pls? Thanks in advance!

For me, I expect list func also can be configured ctx parameter, like this:

func (r *Remote) list(ctx context.Context, o *ListOptions) (rfs []*plumbing.Reference, err error) {
    ... ...
    ... ...
    ar, err := s.AdvertisedReferencesContext(ctx)
    if err != nil {
          return nil, err
    }
   ... ....
   ... ....
}

So that we can control git ls-remote command timeout within several seconds. How do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

FetchContext and PushContext exist, but there's no ListContext method. That's a reasonable thing to add, it's just not part of this PR, which is doing the plumbing.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for your reply! Could you please also help add ListContext func? Or may I submit a new PR based on your changes? But this requires your PR is merged, not sure how long it will take?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd put the API change in a separate MR. No idea how long it will take somebody to get around to merging this one.

Copy link
Contributor

@xiujuan95 xiujuan95 Mar 12, 2021

Choose a reason for hiding this comment

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

Hope this PR can be merged soon!!!! By the way, about API change PR, do you want to own it? If not, I can do it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hi, could you please add a test as @mcuadros said so that this PR can be merged? Because in our environment, this feature is needed and lack of it iss causing some problems for us. Thanks in advance!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You can do the API change, I don't need it myself.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok, thanks!

@mcuadros
Copy link
Member

Sorry for the late review, I will happy to merge this if you add a test to ensure the context propagation.

@asuffield
Copy link
Contributor Author

Sorry for the late review, I will happy to merge this if you add a test to ensure the context propagation.

The existing tests already covered this reasonably well - I had just fixed them to ensure that context propagates, rather than ensuring that it does not. I made a second pass and added a couple more cases, did you have any more specific in mind?

@xiujuan95
Copy link
Contributor

Any updates about this PR?

@mcuadros
Copy link
Member

mcuadros commented Mar 25, 2021

The existing tests already covered this reasonably well - I had just fixed them to ensure that context propagates, rather than ensuring that it does not. I made a second pass and added a couple more cases, did you have any more specific in mind?

We need a test that fails with the old behavior, to validate that we pass properly the context.

@asuffield
Copy link
Contributor Author

We need a test that fails with the old behavior, to validate that we pass properly the context.

The existing tests do this. For example, TestPlainCloneContextNonExistingOverExistingGitDirectory. Fixing those tests to defer cancel() instead of calling it immediately is functionally inverting the test so that it verifies the context is passed, instead of verifying that the context is not passed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants