Skip to content

Commit

Permalink
Revert "wsd: replace _closed member with invalidating the FD"
Browse files Browse the repository at this point in the history
This reverts commit 16a81e9. It
introduced a leak of fds, reproducible using:

(cd test; CPPUNIT_TEST_NAME=HttpRequestTests::test500GetStatuses ./unithttplib)

when the fd limit is 1024 (not visible with 2048).

Just revert on this co-24.04 branch and then do what
<#10971 (comment)>
suggests on master.

Signed-off-by: Miklos Vajna <[email protected]>
Change-Id: Id49aaa432fe20ca3ba0261714cd52e8721f18fe6
  • Loading branch information
vmiklos committed Jan 21, 2025
1 parent e0c8906 commit 18a1607
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions net/Socket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ class Socket
: _type(type)
, _clientPort(0)
, _fd(createSocket(type))
, _closed(_fd < 0)
, _creationTime(creationTime)
, _lastSeenTime(_creationTime)
, _bytesSent(0)
Expand All @@ -171,8 +172,8 @@ class Socket
}
}

/// Returns true iff this socket has been closed or is invalid.
bool isClosed() const { return _fd < 0; }
/// Returns true if this socket has been closed, i.e. rejected from polling and potentially shutdown
bool isClosed() const { return _closed; }

constexpr Type type() const { return _type; }
constexpr bool isIPType() const { return Type::IPv4 == _type || Type::IPv6 == _type; }
Expand Down Expand Up @@ -220,11 +221,11 @@ class Socket
if (!_noShutdown)
{
LOG_TRC("Socket shutdown RDWR. " << *this);
setClosed();
if constexpr (!Util::isMobileApp())
::shutdown(_fd, SHUT_RDWR);
else
fakeSocketShutdown(_fd);
setClosed(); // Invalidate the FD.
}
}

Expand Down Expand Up @@ -417,6 +418,7 @@ class Socket
: _type(type)
, _clientPort(0)
, _fd(fd)
, _closed(_fd < 0)
, _creationTime(creationTime)
, _lastSeenTime(_creationTime)
, _bytesSent(0)
Expand All @@ -436,7 +438,7 @@ class Socket
void setNoShutdown() { _noShutdown = true; }

/// Explicitly marks this socket closed, i.e. rejected from polling and potentially shutdown
void setClosed() { _fd = -1; }
void setClosed() { _closed = true; }

/// Explicitly marks this socket and the given SocketDisposition closed
void setClosed(SocketDisposition &disposition) { setClosed(); disposition.setClosed(); }
Expand Down Expand Up @@ -476,7 +478,9 @@ class Socket
std::string _clientAddress;
const Type _type;
unsigned int _clientPort;
int _fd; ///< The socket file-descriptor. Invalid/closed if < 0.
const int _fd;
/// True if this socket is closed.
bool _closed;

const std::chrono::steady_clock::time_point _creationTime;
std::chrono::steady_clock::time_point _lastSeenTime;
Expand Down

0 comments on commit 18a1607

Please sign in to comment.