]> git.ipfire.org Git - thirdparty/squid.git/commit
Do not "open" Comm::Connection on oldAccept() errors (#1103)
authorAlex Rousskov <rousskov@measurement-factory.com>
Tue, 9 Aug 2022 03:22:48 +0000 (03:22 +0000)
committerSquid Anubis <squid-anubis@squid-cache.org>
Tue, 9 Aug 2022 18:53:33 +0000 (18:53 +0000)
commit7185c9e7dabe76fce29ea527c52b6053e53493a5
treec885a6b9d3cd170a419ad0e1ff5a492223af3864
parent4a28fc5546e36182eaf0beea1818f25587d34e3f
Do not "open" Comm::Connection on oldAccept() errors (#1103)

When Comm::TcpAcceptor::oldAccept() discovers an error, it should close
the socket it just accepted. We should use RAII to avoid leaking the
open socket, especially in the presence of multiple error detection
areas and C++ exceptions. Using the available Connection object for
controlling socket lifetime does not work well because that Connection
object often lingers well past oldAccept() -- the object delivers
various low-level error details (e.g., the remote HTTP client address of
the failed attempt) to TcpAcceptor users.

Instead of "opening" the Connection object ASAP to avoid FD leaks and
then struggling to find the right time to close it, we now delay that
opening until oldAccept() succeeds. Meanwhile, the socket lifetime and
Comm registration are controlled by a simple RAII Descriptor object.

Eventually, we will reuse Comm::Descriptor in Connection and other
descriptor-owning code. One known prerequisite for those improvements is
Optional<> support for non-trivial types (a work in progress).
src/comm/TcpAcceptor.cc
src/fd.cc
src/fd.h