if (conn->matchesTLVs(tlvs)) {
DEBUGLOG("Got one owned connection accepting more for " << backend->getName());
conn->setReused();
+ ++backend->tcpReusedConnections;
return {conn, tlvsMismatch};
}
DEBUGLOG("Found one connection to " << backend->getName() << " but with different TLV values");
auto [downstream, tlvsMismatch] = getOwnedDownstreamConnection(d_ownedConnectionsToBackend, backend, tlvs);
if (!downstream) {
+ if (backend->d_config.useProxyProtocol && tlvsMismatch) {
+ clearOwnedDownstreamConnections(backend);
+ }
+
/* we don't have a connection to this backend owned yet, let's get one (it might not be a fresh one, though) */
downstream = t_downstreamTCPConnectionsManager.getConnectionToDownstream(d_threadData.mplexer, backend, now, std::string());
// if we had an existing connection but the TLVs are different, they are likely unique per query so do not bother keeping the connection
}
}
+void IncomingTCPConnectionState::clearOwnedDownstreamConnections(const std::shared_ptr<DownstreamState>& downstream)
+{
+ d_ownedConnectionsToBackend.erase(downstream);
+}
+
/* called when the buffer has been set and the rules have been processed, and only from handleIO (sometimes indirectly via handleQuery) */
IOState IncomingTCPConnectionState::sendResponse(const struct timeval& now, TCPResponse&& response)
{
std::shared_ptr<TCPConnectionToBackend> getDownstreamConnection(std::shared_ptr<DownstreamState>& backend, const std::unique_ptr<std::vector<ProxyProtocolValue>>& tlvs, const struct timeval& now);
void registerOwnedDownstreamConnection(std::shared_ptr<TCPConnectionToBackend>& conn);
+ void clearOwnedDownstreamConnections(const std::shared_ptr<DownstreamState>& downstream);
static size_t clearAllDownstreamConnections();