-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Fix redirect timeout on renamed repositories #1411
Fix redirect timeout on renamed repositories #1411
Conversation
…imeout-getting-multiple-repositories
…imeout-getting-multiple-repositories
30f058e
to
f3efff1
Compare
} | ||
newRequest.RequestUri = response.Headers.Location; | ||
|
||
if (string.Compare(newRequest.RequestUri.Host, newRequest.RequestUri.Host, StringComparison.OrdinalIgnoreCase) != 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is comparing the same variable. the old code was newRequest
vs request
I have just been troubleshooting a problem with the GitHub Enterprise management console stuff I'm implementing at the moment, where I was getting hanging tasks in my integration tests... it turns out it's the same problem you are fixing here! 😀 (management console uses redirects which as we've seen seems to trigger this behaviour). The good news is, with your fix in place (modified a bit) I no longer get the deadlock 😀 Your code changes were pretty hard to diff due to moving the functions around in the file. I actually re-organised it so the I fixed these locally, plus fixed up a few async/await type issues and renamed There is still the matter of other failed unit tests around redirects and so on to tackle though... |
I rewrite the failed unit tests |
Just throwing myself on as a reminder to sit down and properly understand this change 🤘 |
@maddin2016 have you had a chance to look at those failing tests? |
Not really. Maybe in the next few days. What i have seen is that we have to completely rewright tests for redirects. Yet they are in |
@maddin2016 I'll look at those failing tests and see if I can help |
Hi @shiftkey. I have sit down and think about these failing redirect tests. Here is an approach in which i have move one test into |
I have try to copy these other tests and have find that is not possible to copy them 1 to 1. Because i always have to create new properties for |
Yeah I dont think we want to add these properties to I had a go at re-jigging the tests with the new redirect handling like you've got in this PR. I found that inside the redirect method, I had to pre-save off the original request's |
…imeout-getting-multiple-repositories
|
||
internal class RedirectHandler : DelegatingHandler | ||
{ | ||
public bool Enabled { get; set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see this value being used anywhere (I suspect it also wasn't used before).
This is fine. I'd rather not break this API now, and come back to it when we want to let people provide their own |
else | ||
{ | ||
unbuffered = true; | ||
//throw new Exception("Cannot redirect a request with an unbuffered body"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💄 let's 🔥 these commented lines
@maddin2016 i like where this is heading, and I think this is close to merging in. I'd like to push this out as a release on it's own so we can verify it in isolation from other features being rolled out 🤘 |
From memory the main issue i found with these changes was that you can no longer "reach in" and access the original request message (response.Request. Content) as it's been disposed. I'm not sure if anything really needs to do this (it was only the integration test that was doing it in our code) |
@ryangribble I'm okay with locking that down if it means resolving this redirect issue - it was supposed to be a black box and I'm not really hearing anyone reimplement our If someone comes up with a good use case for needing to poke the request content after we lock this down, then I'm all ears... |
@shiftkey this means these changes from @ryangribble are ok? |
@maddin2016 yep, those comments are fine. Just a couple of tweaks I think to get this ready to merge. |
Something I can do to get ready? |
@maddin2016 I guess @shiftkey talking about his comments in your last commits. If you delete commented/dead code and do something else it can be merged. |
Hey so I pulled these changes down and was going through things one final time and I decided to unskip the failing test from #874 now that we "should" be handling redirects properly. And unfortunately it failed 😡 The problem was something related to the way I had saved off the content stream from the original request, and the new content still had a reference to that old stream. So anyway, I did some more digging and have come up with a revised implementation that doesn't have issues with content streams and looks tidier too. With this fix all the existing tests are passing and unskipping the one from #874 now works too 👍 The commit is TattsGroup@168ea41, if you wanted to cherrypick it @maddin2016 and take a look? |
…se it later Now the skipped test from octokit#874 works! Also had to fix the new ReturnsRenamedRepository test as the ionide repo was renamed again
Hi @ryangribble, do you mean test // Send initial response
var response = await _http.SendAsync(request, HttpCompletionOption.ResponseContentRead, cancellationToken).ConfigureAwait(false);
// Can't redirect without somewhere to redirect to.
if (response.Headers.Location == null)
{
return response;
}
// Clone the request/content incase we get a redirect
var clonedRequest = await CloneHttpRequestMessageAsync(request); |
That's the whole problem, you can't get the content stream ad it's been disposed |
Ok, that makes sense |
@maddin2016 were you happy with that change? Can you confirm all the related integration tests are working for you, including the one I unskipped? |
All tests including that one you have uncomment work for me. So i think we're done, right? |
Awesome stuff, I'll merge this in then |
This fixes #534 via octokit/octokit.net#1411. Previously the request to /site/sha to detect an enterprise instance wasn't getting sent due to octokit's implementation of `RedirectHandler`.
fixed #1396
Put logic for redirects outside delegatinghandler in
HttpClientAdapter
.