{"id":392,"date":"2009-02-24T20:03:12","date_gmt":"2009-02-24T20:03:12","guid":{"rendered":"http:\/\/kera.name\/articles\/?p=392"},"modified":"2009-02-24T20:03:12","modified_gmt":"2009-02-24T20:03:12","slug":"trial-by-proxy","status":"publish","type":"post","link":"https:\/\/kera.name\/articles\/2009\/02\/trial-by-proxy\/","title":{"rendered":"Trial By Proxy"},"content":{"rendered":"<p><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/kera.name\/articles\/wp-content\/uploads\/2007\/09\/firefox.png\" alt=\"\" title=\"Firefox logo large\" width=\"128\" height=\"128\" align=\"right\" \/>I&#039;m sitting on a large University network, over which all HTTP access must be routed through a proxy server. The proxy server performs load balancing, content filtering, virus scan injection on certain content types and the like, and connections cannot be made to remote port 80 through the network without using it.<\/p>\n<p>This isn&#039;t a problem as long as you configure your web browser (and any other web client) to make HTTP requests through the proxy.<\/p>\n<p>Now, recently I noticed that my Firefox 3.0.6 had developed an irritating tendency to briefly hang upon connecting to certain websites. I couldn&#039;t observe a noticeable pattern in which sites were affected, but it seemed to be a pretty consistent problem. The little hangs were hindering my workflow by introducing multi-second wait times during general use of the web.<\/p>\n<p>However I eventually developed a theory which \u2014 directly or indirectly \u2014 might lead to a nice solution.<\/p>\n<p>My theory is based on the notion of the University&#039;s HTTP proxy being horrendously overloaded, which is already clearly evident in its general performance. Dropped connections and temporary unavailability of sites are fairly common, especially in the early evening when Nottingham&#039;s 10,000 students on campus get home from Uni and start scouring the net before dinner.<\/p>\n<p>It&#039;s not a stretch to suggest that any DNS lookups performed by the same server might be somewhat latent. Where do DNS lookups come into it? Observe.<\/p>\n<p><!--nextpage--><\/p>\n<p>Take a typical HTTP v1.1 GET request, without using an HTTP proxy.<\/p>\n<p>The browser first determines the IP address associated with <code>www.google.com<\/code> with a DNS lookup (or possibly a cache hit). It then connects to the server at that IP address on port 80 and sends something like the following:<\/p>\n<blockquote><p>GET http:\/\/www.google.com\/search?q=lolphin HTTP\/1.1<br \/>\nHost: www.google.com<br \/>\nConnection: close<\/p><\/blockquote>\n<p>The fully qualified path is included in the request to allow for server virtualisation; these days one IP address may host many different sites with different domains, so the domain name must be sent in the request to make clear to the server which domain name was entered by the user.<\/p>\n<p>When an HTTP proxy is used the request is the same, but instead of connecting to the IP address obtained by resolving <code>www.google.com<\/code> a client connects to the IP address of the desired proxy server. It may need to resolve a domain like <code>myproxy.mynetwork.com<\/code> to get that IP address, but it <i>never resolves the IP address of <code>www.google.com<\/code><\/i> in this scenario. It doesn&#039;t need to.<\/p>\n<p>The HTTP proxy receives the request, performs the DNS lookup itself and performs the steps required to retrieve the webpage just as if it were a normal web client sending a typical request.<\/p>\n<p>But that lookup performed by the proxy server is the clincher. Because the University proxy here is so overwhelmed by traffic and presumably runs on inadequate hardware, it takes longer than usual for the DNS lookup to be performed.<\/p>\n<p>This might manifest simply as an added delay in connection times when retrieving webpages through the proxy, but apparently Firefox 3.0.6 hangs whilst waiting for a response from a proxy. The result is several seconds of wait time, during which Firefox becomes unresponsive.<\/p>\n<p>(I have no actual evidence for this other than my own experience; if anyone fancies poring through Bugzilla and finding any relevant extant bug report please leave a comment on this article.)<\/p>\n<p><!--nextpage--><\/p>\n<p>One way around this problem is to prevent the HTTP proxy from having to perform the DNS lookup at all.<\/p>\n<p>Notice that in the HTTP request we specify the domain name of the website twice: in the URL; and in the &#034;Host&#034; directive. The proxy [should] resolve the domain found in the URL (not the &#034;Host&#034; directive, which is purely information for the web server), but if this domain is actually already an IP address then no lookup is necessary.<\/p>\n<blockquote><p>GET http:\/\/123.45.678.90\/search?q=lolphin HTTP\/1.1<br \/>\nHost: www.google.com<br \/>\nConnection: close<\/p><\/blockquote>\n<p>The &#034;Host&#034; directive is left untouched so the web server still knows what domain name we want to access.<\/p>\n<p>Unfortunately Firefox itself doesn&#039;t provide a way to force this behaviour; Firefox <i>always<\/i> performs DNS lookups through a proxy server if you&#039;ve defined one.<\/p>\n<p><b>Update:<\/b> It&#039;s a known bug [1] \u2014 apparently relevant only when using an automatic proxy configuration file (&#034;.pac&#034;) \u2014 that&#039;s being tracked [2]. It seems the lookups in the PAC specifically are the problem; these are what Firefox uses to determine what proxy server to use based on the requested site&#039;s address.<\/p>\n<p>In the meantime the problem can be alleviated by entering proxy details directly in the &#034;Manual Proxy Configuration&#034; area; this is not a robust solution as any changes to the network configuration could render your manual configuration obsolete. However it will prevent proxied lookups from blocking the browser&#039;s main thread, which causes a momentary hang.<\/p>\n<hr \/>\n<p>[1] <a href=\"http:\/\/kb.mozillazine.org\/Firefox_hangs#Hang_loading_websites_when_using_an_automatic_proxy_configuration_file\"><a href=\"http:\/\/kb.mozillazine.org\/Firefox_hangs\">http:\/\/kb.mozillazine.org\/Firefox_hangs<\/a><\/a><br \/>\n[2] <a href=\"https:\/\/bugzilla.mozilla.org\/show_bug.cgi?id=235853\"><a href=\"https:\/\/bugzilla.mozilla.org\/show_bug.cgi?id=235853\">https:\/\/bugzilla.mozilla.org\/show_bug.cgi?id=235853<\/a><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I explore the foibles of DNS lookups with proxy servers in Firefox 3, and try to determine why they cause my browser to hang intermittently.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[40,9,16],"_links":{"self":[{"href":"https:\/\/kera.name\/articles\/wp-json\/wp\/v2\/posts\/392"}],"collection":[{"href":"https:\/\/kera.name\/articles\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kera.name\/articles\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kera.name\/articles\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kera.name\/articles\/wp-json\/wp\/v2\/comments?post=392"}],"version-history":[{"count":5,"href":"https:\/\/kera.name\/articles\/wp-json\/wp\/v2\/posts\/392\/revisions"}],"predecessor-version":[{"id":397,"href":"https:\/\/kera.name\/articles\/wp-json\/wp\/v2\/posts\/392\/revisions\/397"}],"wp:attachment":[{"href":"https:\/\/kera.name\/articles\/wp-json\/wp\/v2\/media?parent=392"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kera.name\/articles\/wp-json\/wp\/v2\/categories?post=392"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kera.name\/articles\/wp-json\/wp\/v2\/tags?post=392"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}