Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3da9249f authored by Mike Yu's avatar Mike Yu Committed by Automerger Merge Worker
Browse files

Fix private DNS not working due to getConnectCounter() stuck am: 568ed6c9

Original change: https://android-review.googlesource.com/c/platform/packages/modules/DnsResolver/+/1354544

Change-Id: I82e479aa58329c48dc8455fb7ea380492b5c99e2
parents 30567641 568ed6c9
Loading
Loading
Loading
Loading
+7 −4
Original line number Original line Diff line number Diff line
@@ -146,8 +146,6 @@ DnsTlsTransport::Response DnsTlsDispatcher::query(const std::list<DnsTlsServer>&
DnsTlsTransport::Response DnsTlsDispatcher::query(const DnsTlsServer& server, unsigned mark,
DnsTlsTransport::Response DnsTlsDispatcher::query(const DnsTlsServer& server, unsigned mark,
                                                  const Slice query, const Slice ans, int* resplen,
                                                  const Slice query, const Slice ans, int* resplen,
                                                  bool* connectTriggered) {
                                                  bool* connectTriggered) {
    int connectCounter;

    // TODO: This can cause the resolver to create multiple connections to the same DoT server
    // TODO: This can cause the resolver to create multiple connections to the same DoT server
    // merely due to different mark, such as the bit explicitlySelected unset.
    // merely due to different mark, such as the bit explicitlySelected unset.
    // See if we can save them and just create one connection for one DoT server.
    // See if we can save them and just create one connection for one DoT server.
@@ -163,13 +161,19 @@ DnsTlsTransport::Response DnsTlsDispatcher::query(const DnsTlsServer& server, un
            xport = it->second.get();
            xport = it->second.get();
        }
        }
        ++xport->useCount;
        ++xport->useCount;
        connectCounter = xport->transport.getConnectCounter();
    }
    }


    // Don't call this function and hold sLock at the same time because of the following reason:
    // TLS handshake requires a lock which is also needed by this function, if the handshake gets
    // stuck, this function also gets blocked.
    const int connectCounter = xport->transport.getConnectCounter();

    LOG(DEBUG) << "Sending query of length " << query.size();
    LOG(DEBUG) << "Sending query of length " << query.size();
    auto res = xport->transport.query(query);
    auto res = xport->transport.query(query);
    LOG(DEBUG) << "Awaiting response";
    LOG(DEBUG) << "Awaiting response";
    const auto& result = res.get();
    const auto& result = res.get();
    *connectTriggered = (xport->transport.getConnectCounter() > connectCounter);

    DnsTlsTransport::Response code = result.code;
    DnsTlsTransport::Response code = result.code;
    if (code == DnsTlsTransport::Response::success) {
    if (code == DnsTlsTransport::Response::success) {
        if (result.response.size() > ans.size()) {
        if (result.response.size() > ans.size()) {
@@ -187,7 +191,6 @@ DnsTlsTransport::Response DnsTlsDispatcher::query(const DnsTlsServer& server, un
    auto now = std::chrono::steady_clock::now();
    auto now = std::chrono::steady_clock::now();
    {
    {
        std::lock_guard guard(sLock);
        std::lock_guard guard(sLock);
        *connectTriggered = (xport->transport.getConnectCounter() > connectCounter);
        --xport->useCount;
        --xport->useCount;
        xport->lastUsed = now;
        xport->lastUsed = now;
        cleanup(now);
        cleanup(now);