[bug] Falling back to a direct connection for HTTPS requests doesn't always work right
For a while now, we've noticed these weird errors in the statshub logs where it looks like the client is making a CONNECT request to statshub. I think I have some idea of what this is.
If a client (like one of our Java HTTP clients) thinks that it's talking to a proxy, and it's trying to make an HTTPS request, it will break this into two steps:
- Make a CONNECT request to the proxy to establish a tunnel
- Send the actual traffic over the tunnel
When the local LittleProxy thinks that it's talking to a chained upstream proxy, it forwards that CONNECT request. Under some circumstances, though, we fall back to direct connections rather than using a chained proxy. If LittleProxy were to get into a state where it thinks it's using a chained proxy but is actually connecting directly to the destination, it will end up making a CONNECT request to that destination.
In this particular case, I think that destination is statshub.
So the question is, how is LittleProxy getting into this state?
@myleshorton I think this is the key to the mysterious CONNECT requests made to statshub. If I'm right, this same root cause could be affecting other traffic as well.
Looks like for statshub we're using HttpURLConnection. If the problem is in that (or our use of it), then this issue is probably isolated to just stats posting and logging (basically, all subclasses of HttpURLClient).
How would LittleProxy ever think it's connecting to a proxy when it's actually connecting directly?
That's the question. One potential scenario is that it tried to connect to a proxy and failed, and then fell back to a direct connection. If it's still in "I'm connecting to a proxy mode" here, that could be the problem.
That said, we already unit test for this, so unless the unit test is broken, there may be something else going on here.
I believe taking LittleProxy out of the proxy chain did not fix this in testing, correct @oxtoacart? If so should we close?
It seems as if this CONNECT versus direct issue results in the SSL errors enumerated in #2007 and #2038. All of them are pending being consistently reproduced and fixed.
This is currently our most reported issue in automated bug reporting, so P1
So the original hypothesis was that the client-side LittleProxy was causing this. Taking it out of the path didn't solve the problem. However, we have not yet tested without client and server-side LittleProxy, so it's possible that there is a LittleProxy issue, just on the server side. It's not immediately clear what the server could be doing wrong to cause this, but it's worth testing by cutting LittleProxy out entirely.
#1510 is yet another incarnation of this same issue. Closing that to make this the canonical ticket.
Makes sense @oxtoacart.
Once https://github.com/getlantern/lantern/pull/2103 is pulled, the impact of this will be dramatically reduced since most proxies will be managed on the Go side. The only exception to this are port-mapped TCP peer proxies.