-
Notifications
You must be signed in to change notification settings - Fork 10.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
UriHelper.GetDisplayUrl() throws NullReferenceException if request is lacking host header #2718
Comments
From @Tratcher on Tuesday, July 12, 2016 7:55:55 PM Was the Host header requirement a 1.1 addition? |
From @mikeharder on Wednesday, July 13, 2016 12:00:45 PM Yes, it's optional in 1.0: https://www.w3.org/Protocols/rfc2616/rfc2616-sec19.html#sec19.6.1 |
From @Tratcher on Wednesday, July 13, 2016 12:08:07 PM Hmm, this method can't generate a complete url without the Host header. Should it throw InvalidOperationException or return an incomplete url like |
From @mikeharder on Wednesday, July 13, 2016 12:12:38 PM Exception seems bad, since every call to this method would need to be wrapped in a try/catch, since the app developer can't control whether clients will send a host header. Could the method use something like |
From @Tratcher on Wednesday, July 13, 2016 12:30:22 PM LocalIp and port are OK, but also optional for servers. They'll also be different when you're behind IIS/Express. Guessing is likely to confuse the user. I'd rather indicate that we didn't know. |
From @mikeharder on Wednesday, July 13, 2016 12:37:38 PM I would just use the incomplete URL then ( |
From @Tratcher on Wednesday, July 13, 2016 1:26:33 PM Yeah. The biggest downside is that it drops information you do know, the scheme. |
From @mikeharder on Wednesday, July 13, 2016 2:05:15 PM Agreed, but since there's no standard for "scheme and path without host", I think |
From @muratg on Monday, July 25, 2016 2:14:01 PM Backlogging for now. If we get enough customer complaint/request, we may reconsider. |
From @Flavien on Sunday, June 25, 2017 5:30:41 PM This issue also manifests if you use |
From @rynowak on Sunday, June 25, 2017 5:49:41 PM Are you trying to do this on a thread that isn't handling a request? None of this stuff is thread safe. |
From @Flavien on Sunday, June 25, 2017 5:53:03 PM Yes, I'm doing this on a thread that isn't handling a request, so I'm not sure why What's not thread safe and why should that have to be thread safe? |
From @Flavien on Sunday, June 25, 2017 5:59:35 PM Ok I see what's going on: I'm creating a |
From @Flavien on Monday, June 26, 2017 3:57:39 AM I am puzzled, how can I start a background task from a request without capturing the I tried everything, and every time, |
From @rynowak on Monday, June 26, 2017 5:04:44 AM
If you want to do some work on a background task you need to capture all of the data you want to see up front and then spawn your task. Doing any access to an If you can share a little more about what you're trying to accomplish we can provide some suggestions. Keep in mind, the server is already massively parallel (many requests) so attempting to parallelize the work of a single request is usually an overall loss of performance. |
From @Flavien on Monday, June 26, 2017 6:22:38 AM I don't care about performance, I just need the request to complete and return 200 to the client while a long running operation continues running on the server for a couple of minutes. This is fairly standard asynchronous API design. I'm trying to access the I haven't found any way to spawn a standalone task detached from the original request. |
From @Tratcher on Monday, June 26, 2017 7:06:01 AM
|
From @Flavien on Monday, June 26, 2017 7:09:42 AM This doesn't seem to exist on .NET Core. |
From @davidfowl on Monday, June 26, 2017 10:23:44 AM @Flavien unfortunately, until .NET Core 2.0 there isn't an easy way to avoid capturing the async local. Here's a sample of what you could do: public class ThreadPoolImpl : IThreadPool
{
private readonly IHttpContextAccessor _httpContextAccessor;
public ThreadPoolImpl(IHttpContextAccessor httpContextAccessor)
{
_httpContextAccessor = httpContextAccessor;
}
public void QueueUserWorkItem(Func<Task> workitem)
{
_ = Execute(workitem);
}
private async Task Execute(Func<Task> workItem)
{
_httpContextAccessor.HttpContext = null;
await workItem();
}
}
public interface IThreadPool
{
void QueueUserWorkItem(Func<Task> workItem);
} Basically just set the |
From @Flavien on Monday, June 26, 2017 2:25:18 PM @davidfowl Thanks that seems to work. What are the mechanics behind |
From @Volak on Friday, December 15, 2017 5:55:12 PM @muratg I want to make a note - hopefully changing the "backlog" status. HaProxy by default will use HTTP/1.0 to do health checks on http servers. See: https://www.haproxy.com/documentation/aloha/7-0/traffic-management/lb-layer7/health-checks/#check-http-service This bug causes the service to report NullReferenceExceptions each and every health check
There is a workaround - instead of using the config line but in my case I have little to no control of haproxy config as its set by another package. I'll have to investigate if there's a way to change this line in their configs |
From @Tratcher on Friday, December 15, 2017 5:58:43 PM https://github.com/aspnet/Hosting/issues/1289 would address this. |
…-master [automated] Merge branch 'release/2.2' => 'master'
Hello, We need to fix this at earliest and for the moment I can retrieve the URL using this code, by manually copy pasting. However, I want to avoid this, considering this is downstream dependency issue and want to prevent behavioral changes for the customers between ASP.NET Core 2.x and 3.x. Any updates are highly appreciated. Thanks, |
I didn't realize this issue was still open. Closing as resolved. PR: aspnet/HttpAbstractions#1057 @yogiraj07 this was not being considered for 2.x servicing. @anurse? |
@yogiraj07 Do you have any information as to the customer impact? (i.e. How many customers you've seen with this issue?). With 3.0 scheduled for the end of the year the bar for backporting to 2.x is pretty high but this is a simple change so it may be feasible if we know more about the customer impact. |
@anurse , I have 2 options in my mind -
The thing is
Any thoughts on this? |
We haven't been able to take this for approval for backporting yet as our window for doing so hasn't opened yet (it should open in the next week or so). If it's approved it'll still be June (at best) before the patch is released. As to how you can work around it, I think that copying the code is your best option here. As you can see, the logic is not very complicated and looking at the history it has had very minimal behavior changes over time. |
From @mikeharder on Tuesday, July 12, 2016 4:42:47 PM
If a client makes a valid HTTP 1.0 request without a host header, UriHelper.GetDisplayUrl() throws NullReferenceException.
Server Code
Client Commands
Server Log
Copied from original issue: aspnet/HttpAbstractions#671
The text was updated successfully, but these errors were encountered: