adamfisk/LittleProxy — Issue #20: HttpServerPipelineFactory doesn't enforce an idle handler, though the client (DefaultRelayPipelineFactory) does
Author: theotherian
Created: 2012-01-27 16:42:38+00:00
State: open

The DefaultRelayPipelineFactory, which is used by connections that go from proxy to the web, specifies an IdleStateHandler and an IdleAwareHandler. There are hardcoded values for read and write timeout of 40 seconds depending on the HTTP method specified (on a side note, this should probably be configurable, and there should probably be a read timeout on PUT and POST as well).

However, on the HttpServerPipelineFactory, there is no idle handling present.

What this means is that you can end up hanging forever on a connection. For example, let's say that Firefox is configured to use a proxy hitting a site called SlowWebsite. Firefox makes a connection to the proxy, which in turn makes a connection to SlowWebsite. SlowWebsite takes longer than 40 seconds to respond and the proxy terminates the connection due to idle state. SlowWebsite tries to respond after 60 seconds, and nothing happens. The connection between Firefox and the proxy is still present, resulting in Firefox never returning ready state for the page because the request is stuck in limbo.

Adding an IdleStateHandler and IdleAwareHandler at a slightly higher threshold (since setting the same would be problematic) in the HttpServerPipelineFactory.getChannel method fixes this issue for me.

On a side note, with the changes I have on my local machine, I also adding logging of the request and referrer to help me debug what resources might be latent if, say, a JavaScript file on a page is taking forever to download.