Unverified Commit eb59e458 authored by Dennis Jenkins's avatar Dennis Jenkins Committed by GitHub

Merge pull request #485 from knowledge4igor/fix_flaky_tests_caused_by_timeout_problem

Fix flaky tests caused by timeout problem
parents 40276083 f4c74ddd
......@@ -231,7 +231,7 @@ private:
: resolve(std::move(resolve))
, reject(std::move(reject))
, connection(connection)
, timer(std::move(timer))
, timer(timer)
, buffer(std::move(buf))
{
}
......@@ -248,7 +248,11 @@ private:
PollableQueue<ConnectionEntry> connectionsQueue;
std::unordered_map<Fd, ConnectionEntry> connections;
std::unordered_map<Fd, std::weak_ptr<Connection>> timeouts;
using Lock = std::mutex;
using Guard = std::lock_guard<Lock>;
Lock timeoutsLock;
void asyncSendRequestImpl(const RequestEntry& req, WriteStatus status = FirstTry);
......
......@@ -156,6 +156,7 @@ Transport::onReady(const Aio::FdSet& fds) {
}
}
else {
Guard guard(timeoutsLock);
auto timerIt = timeouts.find(fd);
if (timerIt != std::end(timeouts))
{
......@@ -163,16 +164,13 @@ Transport::onReady(const Aio::FdSet& fds) {
if (connection)
{
handleTimeout(connection);
timeouts.erase(fd);
}
else
{
throw std::runtime_error("Connection error: problem with handling timeout");
}
}
else
{
throw std::runtime_error("Unknown fd");
}
}
}
else {
......@@ -223,7 +221,7 @@ Transport::asyncSendRequest(
return Async::Promise<ssize_t>([&](Async::Resolver& resolve, Async::Rejection& reject) {
auto ctx = context();
RequestEntry req(std::move(resolve), std::move(reject), connection, std::move(timer), std::move(buffer));
RequestEntry req(std::move(resolve), std::move(reject), connection, timer, std::move(buffer));
if (std::this_thread::get_id() != ctx.thread()) {
requestsQueue.push(std::move(req));
} else {
......@@ -266,6 +264,7 @@ Transport::asyncSendRequestImpl(
totalWritten += bytesWritten;
if (totalWritten == len) {
if (req.timer) {
Guard guard(timeoutsLock);
timeouts.insert(
std::make_pair(req.timer->fd, conn));
req.timer->registerReactor(key(), reactor());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment