------------------------------------------------------------ revno: 13851 revision-id: squid3@treenet.co.nz-20150628100915-9vpx0lg2avtxda4c parent: squid3@treenet.co.nz-20150628100558-bn224a6mbjwehk18 committer: Amos Jeffries branch nick: 3.5 timestamp: Sun 2015-06-28 03:09:15 -0700 message: Fix CONNECT failover to IPv4 after trying broken IPv6 servers This makes CONNECT tunnel connection attempts obey forward_timeout and continue retrying instead of aborting with a client error when one possible server hits a connect_timeout. ------------------------------------------------------------ # Bazaar merge directive format 2 (Bazaar 0.90) # revision_id: squid3@treenet.co.nz-20150628100915-9vpx0lg2avtxda4c # target_branch: http://bzr.squid-cache.org/bzr/squid3/3.5 # testament_sha1: 08ec580a9986cde73c4f6651b1db2189cf56a949 # timestamp: 2015-06-28 10:15:48 +0000 # source_branch: http://bzr.squid-cache.org/bzr/squid3/3.5 # base_revision_id: squid3@treenet.co.nz-20150628100558-\ # bn224a6mbjwehk18 # # Begin patch === modified file 'src/tunnel.cc' --- src/tunnel.cc 2015-03-13 11:24:18 +0000 +++ src/tunnel.cc 2015-06-28 10:09:15 +0000 @@ -155,6 +155,7 @@ LogTags *logTag_ptr; ///< pointer for logging Squid processing code MemBuf *connectRespBuf; ///< accumulates peer CONNECT response when we need it bool connectReqWriting; ///< whether we are writing a CONNECT request to a peer + time_t started; ///< when this tunnel was initiated. void copyRead(Connection &from, IOCB *completion); @@ -875,13 +876,20 @@ /* At this point only the TCP handshake has failed. no data has been passed. * we are allowed to re-try the TCP-level connection to alternate IPs for CONNECT. */ + debugs(26, 4, "removing server 1 of " << tunnelState->serverDestinations.size() << + " from destinations (" << tunnelState->serverDestinations[0] << ")"); tunnelState->serverDestinations.erase(tunnelState->serverDestinations.begin()); - if (status != Comm::TIMEOUT && tunnelState->serverDestinations.size() > 0) { + time_t fwdTimeout = tunnelState->started + Config.Timeout.forward; + if (fwdTimeout > squid_curtime && tunnelState->serverDestinations.size() > 0) { + // find remaining forward_timeout available for this attempt + fwdTimeout -= squid_curtime; + if (fwdTimeout > Config.Timeout.connect) + fwdTimeout = Config.Timeout.connect; /* Try another IP of this destination host */ GetMarkingsToServer(tunnelState->request.getRaw(), *tunnelState->serverDestinations[0]); debugs(26, 4, HERE << "retry with : " << tunnelState->serverDestinations[0]); AsyncCall::Pointer call = commCbCall(26,3, "tunnelConnectDone", CommConnectCbPtrFun(tunnelConnectDone, tunnelState)); - Comm::ConnOpener *cs = new Comm::ConnOpener(tunnelState->serverDestinations[0], call, Config.Timeout.connect); + Comm::ConnOpener *cs = new Comm::ConnOpener(tunnelState->serverDestinations[0], call, fwdTimeout); cs->setHost(tunnelState->url); AsyncJob::Start(cs); } else { @@ -981,6 +989,7 @@ tunnelState->client.conn = http->getConn()->clientConnection; tunnelState->http = http; tunnelState->al = al; + tunnelState->started = squid_curtime; comm_add_close_handler(tunnelState->client.conn->fd, tunnelClientClosed,