Commit e79f7fa7 authored by jan.koester's avatar jan.koester
Browse files

test

parent 7927c590
Loading
Loading
Loading
Loading
+26 −0
Changes for src/http/HttpProxyServer.cpp: 26 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -151,6 +151,32 @@ namespace {
constexpr size_t kMinCompressibleBytes = 256;
} // namespace

namespace {
// Guarantees LoadBalancer::release() runs exactly once for whatever pick() returned,
// regardless of how RequestEvent exits afterward (normal return, an early return, or an
// exception unwinding past the two explicit release() call sites that used to be the only
// path -- e.g. a future edit adding a throwing call between pick() and either call site would
// silently skip release(), corrupting the pool's LeastConnections/health-cooldown accounting).
// Inert (no-op destructor) until arm() is called, so declaring one unconditionally at the top
// of RequestEvent and only arming it once pick() actually succeeds is safe.
struct ScopedLbRelease {
    proxyplus::lb::LoadBalancer *lb = nullptr;
    std::string pool;
    std::string target;
    bool ok = false;

    void arm(proxyplus::lb::LoadBalancer &loadBalancer, std::string poolName, std::string targetName) {
        lb = &loadBalancer;
        pool = std::move(poolName);
        target = std::move(targetName);
    }

    ~ScopedLbRelease() {
        if (lb) lb->release(pool, target, ok);
    }
};
} // namespace

void HttpProxyController::applyResponseCompression(libhttppp::HttpRequest &curreq,
                                                     const std::string &upstreamEncoding,
                                                     std::vector<char> &body,