Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Private/mmeeks/debongmore #10334

Merged
merged 3 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ else
# Use coolwsd to cleanup jails, if any. If it fails, we may have a broken/old coolwsd binary, remove it to rebuild.
# A CI box may switch branches without cleaning up the binaries, if coolwsd from a broken branch is used here
# it will fail all subsequent builds, until it's rebuilt from the new branch. So removing coolwsd after failing is needed.
CLEANUP_COMMAND=if test -s ./coolwsd; then echo "Cleaning up..." && ./coolwsd --disable-cool-user-checking --cleanup --o:logging.level=trace || rm -f ./coolwsd; fi
CLEANUP_COMMAND=if test -s ./coolwsd -a -x ./coolwsd; then echo "Cleaning up..." && ./coolwsd --disable-cool-user-checking --cleanup --o:logging.level=trace || rm -f ./coolwsd; fi
endif

CLEANUP_COVERAGE=rm -rf ${abs_top_srcdir}/gcov; find . -iname "*.gc??" -delete
Expand Down
58 changes: 29 additions & 29 deletions net/Socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1480,40 +1480,40 @@ std::ostream& StreamSocket::stream(std::ostream& os) const

bool StreamSocket::checkRemoval(std::chrono::steady_clock::time_point now)
{
if( isIPType() )
{
// Forced removal on outside-facing IPv[46] network connections only
const auto durLast =
std::chrono::duration_cast<std::chrono::milliseconds>(now - getLastSeenTime());
/// TO Criteria: Violate maximum idle (_pollTimeout default 64s)
const bool isIdle = _pollTimeout > std::chrono::microseconds::zero() &&
durLast > _pollTimeout;
/// TO Criteria: Shall terminate?
const bool isTermination = SigUtil::getTerminationFlag();
if (isIdle || isTermination )
if( !isIPType() )
return false;

// Forced removal on outside-facing IPv[46] network connections only
const auto durLast =
std::chrono::duration_cast<std::chrono::milliseconds>(now - getLastSeenTime());
/// TO Criteria: Violate maximum idle (_pollTimeout default 64s)
const bool isIdle = _pollTimeout > std::chrono::microseconds::zero() &&
durLast > _pollTimeout;
/// TO Criteria: Shall terminate?
const bool isTermination = SigUtil::getTerminationFlag();
if (isIdle || isTermination )
{
LOG_WRN("CheckRemoval: Timeout: {Idle " << isIdle
<< ", Termination " << isTermination << "}, "
<< getStatsString(now) << ", "
<< *this);
if (_socketHandler)
{
LOG_WRN("CheckRemoval: Timeout: {Idle " << isIdle
<< ", Termination " << isTermination << "}, "
<< getStatsString(now) << ", "
<< *this);
if (_socketHandler)
{
_socketHandler->onDisconnect();
if( isOpen() ) {
// Note: Ensure proper semantics of onDisconnect()
LOG_WRN("Socket still open post onDisconnect(), forced shutdown.");
shutdown(); // signal
closeConnection(); // real -> setClosed()
}
}
else
{
_socketHandler->onDisconnect();
if( isOpen() ) {
// Note: Ensure proper semantics of onDisconnect()
LOG_WRN("Socket still open post onDisconnect(), forced shutdown.");
shutdown(); // signal
closeConnection(); // real -> setClosed()
}
assert(isOpen() == false); // should have issued shutdown
return true;
}
else
{
shutdown(); // signal
closeConnection(); // real -> setClosed()
}
assert(isOpen() == false); // should have issued shutdown
return true;
}
return false;
}
Expand Down
32 changes: 20 additions & 12 deletions net/WebSocketHandler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,8 @@ class WebSocketHandler : public ProtocolHandlerInterface

void shutdown(bool goingAway, const std::string &statusMessage) override
{
shutdownImpl(goingAway ? WebSocketHandler::StatusCodes::ENDPOINT_GOING_AWAY :
shutdownImpl(_socket.lock(),
goingAway ? WebSocketHandler::StatusCodes::ENDPOINT_GOING_AWAY :
WebSocketHandler::StatusCodes::NORMAL_CLOSE, statusMessage,
/*hardShutdown=*/ false, /*silentShutdown=*/ false);
}
Expand All @@ -247,13 +248,15 @@ class WebSocketHandler : public ProtocolHandlerInterface
const std::string& statusMessage = std::string(),
bool hardShutdown = false)
{
shutdownImpl(statusCode, statusMessage, hardShutdown, false);
shutdownImpl(_socket.lock(),
statusCode, statusMessage, hardShutdown, false);
}

/// Don't wait for the remote Websocket to handshake with us; go down fast.
void shutdownAfterWriting()
{
shutdownImpl(WebSocketHandler::StatusCodes::NORMAL_CLOSE, std::string(),
shutdownImpl(_socket.lock(),
WebSocketHandler::StatusCodes::NORMAL_CLOSE, std::string(),
true /* hard async shutdown & close */, false);
}

Expand All @@ -265,18 +268,19 @@ class WebSocketHandler : public ProtocolHandlerInterface
}

private:
void shutdownSilent()
void shutdownSilent(const std::shared_ptr<StreamSocket>& socket)
{
shutdownImpl(WebSocketHandler::StatusCodes::POLICY_VIOLATION /* ignored */,
shutdownImpl(socket,
WebSocketHandler::StatusCodes::POLICY_VIOLATION /* ignored */,
std::string(), true /* hard async shutdown & close */, true);
}

void shutdownImpl(const StatusCodes statusCode,
void shutdownImpl(const std::shared_ptr<StreamSocket>& socket,
const StatusCodes statusCode,
const std::string& statusMessage,
bool hardShutdown,
bool silentShutdown)
{
std::shared_ptr<StreamSocket> socket = _socket.lock();
if (socket)
{
const bool silent = _shuttingDown || silentShutdown;
Expand Down Expand Up @@ -671,11 +675,15 @@ class WebSocketHandler : public ProtocolHandlerInterface
if (_pingTimeout.count() > std::numeric_limits<double>::epsilon() &&
_pingMicroS.average() >= _pingTimeout.count())
{
LOG_WRN("CheckTimeout: Timeout websocket: Ping: last " << _pingMicroS.last() << "us, avg "
<< _pingMicroS.average() << "us >= " << _pingTimeout.count() << "us over "
<< (int)_pingMicroS.duration() << "s");
shutdownSilent();
return true;
std::shared_ptr<StreamSocket> socket = _socket.lock();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the lock and the copy when this comes in as a parameter ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm quite disturbed by closing connections on longer average pings too - where does that come from ?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm quite disturbed by closing connections on longer average pings too - where does that come from ?

I described the source (and idea) of WS ping TO instrument #10334 (comment) as well as wrapped it up in #10337

I am currently about to finish my draft PR for #10337 and will post its initial version,
currently refining the UTs for it.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the lock and the copy when this comes in as a parameter ?

the _socket.lock() has moved up to checkTimeout to cover for the socket->isIPType() check, which you have correctly introduced with your change request (but not coded all out).

if (socket && socket->isIPType()) // Exclude non-IP local sockets
{
LOG_WRN("CheckTimeout: Timeout websocket: Ping: last " << _pingMicroS.last() << "us, avg "
<< _pingMicroS.average() << "us >= " << _pingTimeout.count() << "us over "
<< (int)_pingMicroS.duration() << "s, " << *socket);
shutdownSilent(socket);
return true;
}
}
if (!_pingMicroS.initialized() || (_pingPeriod > std::chrono::microseconds::zero() &&
now - _pingMicroS.lastTime() >= _pingPeriod))
Expand Down
Loading