Commit 4eea01d3 authored by jan.koester's avatar jan.koester
Browse files

Revert "test"

This reverts commit aee7d10b.
parent 7e1eb468
Loading
Loading
Loading
Loading
Loading
+3 −35
Original line number Diff line number Diff line
@@ -354,9 +354,8 @@ public:
                sha512 sha;
                sha.hash(pw, pwsalt);

                auto tryClientLookup = [&](bool &foundClient) -> const ClientConnections* {
                    foundClient = false;

                // O(1) indexed lookup by clientname instead of O(n) scan
                {
                    AuthBackend::Guard guard(_Backend, AuthBackend::Shared);
                    RecordIndex &idx = _Backend.getIndex();
                    if (!idx.valid() || idx.revision() != _Backend.getRevesion())
@@ -364,7 +363,6 @@ public:

                    uuid::uuid found_clid;
                    if (idx.findByName(DataType::ClientData, "clientname", name, found_clid)) {
                        foundClient = true;
                        class ClientData cdat(found_clid);
                        size_t upos = sizeof(AuthHeader);
                        AuthClient.info(_Backend, cdat, upos);
@@ -378,39 +376,9 @@ public:
                            json_object_array_add(response, respid);
                            return cid;
                        }
                        return nullptr; // wrong secret
                    }

                    return nullptr;
                };

                bool foundClient = false;
                if (const ClientConnections *conn = tryClientLookup(foundClient))
                    return conn;

                // Recovery path for observed degraded state: under heavy request load
                // the backend can require compaction before name lookups are reliable.
                // Only run this when the client record wasn't found at all.
                if (!foundClient && _Backend.getType() == AuthBackendType::File) {
                    try {
                        size_t sizeBefore = 0;
                        size_t sizeAfter = 0;
                        _Backend.vacuum(sizeBefore, sizeAfter);
                        _Backend.getIndex().invalidate();
                        std::cerr << "[api] client auth recovery vacuum: "
                                  << sizeBefore << " -> " << sizeAfter << std::endl;
                    } catch (const std::exception &e) {
                        std::cerr << "[api] client auth recovery failed: "
                                  << e.what() << std::endl;
                    } catch (...) {
                        std::cerr << "[api] client auth recovery failed: unknown error"
                                  << std::endl;
                }

                    if (const ClientConnections *conn = tryClientLookup(foundClient))
                        return conn;
                }

                return nullptr; // not found or wrong secret
            }
        }
        return nullptr;