mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Don't use JobQueue during shutdown (RIPD-1356):
If the JobQueue is used during shutdown then those Jobs may access Stoppables after they have already stopped. This violates the preconditions of Stoppables and may lead to undefined behavior. The solution taken here is to reference count all Jobs in the JobQueue. At stop time all Jobs already in the JobQueue are allowed to run to completion, but no further Jobs are allowed into the JobQueue. If a Job is rejected from the JobQueue (because we are stopping), then JobQueue::addJob() returns false, so the caller can make any necessary adjustments.
This commit is contained in:
@@ -309,11 +309,20 @@ ServerHandlerImp::onRequest (Session& session)
|
||||
return;
|
||||
}
|
||||
|
||||
m_jobQueue.postCoro(jtCLIENT, "RPC-Client",
|
||||
[this, detach = session.detach()](std::shared_ptr<JobQueue::Coro> c)
|
||||
std::shared_ptr<Session> detachedSession = session.detach();
|
||||
auto const postResult = m_jobQueue.postCoro(jtCLIENT, "RPC-Client",
|
||||
[this, detachedSession](std::shared_ptr<JobQueue::Coro> coro)
|
||||
{
|
||||
processSession(detach, c);
|
||||
processSession(detachedSession, coro);
|
||||
});
|
||||
if (postResult == nullptr)
|
||||
{
|
||||
// The coroutine was rejected, probably because we're shutting down.
|
||||
HTTPReply(503, "Service Unavailable",
|
||||
makeOutput(*detachedSession), app_.journal("RPC"));
|
||||
detachedSession->close(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
@@ -350,12 +359,12 @@ ServerHandlerImp::onWSMessage(
|
||||
JLOG(m_journal.trace())
|
||||
<< "Websocket received '" << jv << "'";
|
||||
|
||||
m_jobQueue.postCoro(jtCLIENT, "WS-Client",
|
||||
[this, session = std::move(session),
|
||||
jv = std::move(jv)](auto const& c)
|
||||
auto const postResult = m_jobQueue.postCoro(jtCLIENT, "WS-Client",
|
||||
[this, session, jv = std::move(jv)]
|
||||
(std::shared_ptr<JobQueue::Coro> const& coro)
|
||||
{
|
||||
auto const jr =
|
||||
this->processSession(session, c, jv);
|
||||
this->processSession(session, coro, jv);
|
||||
auto const s = to_string(jr);
|
||||
auto const n = s.length();
|
||||
beast::multi_buffer sb(n);
|
||||
@@ -365,6 +374,11 @@ ServerHandlerImp::onWSMessage(
|
||||
StreambufWSMsg<decltype(sb)>>(std::move(sb)));
|
||||
session->complete();
|
||||
});
|
||||
if (postResult == nullptr)
|
||||
{
|
||||
// The coroutine was rejected, probably because we're shutting down.
|
||||
session->close();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
Reference in New Issue
Block a user