Victor
Victor

Reputation: 183

How do I make my logical server always connect successfully to data on my database server (ArangoDB)?

I have a server that has a web app on it. This server needs to access data on a different server that holds my database. Sometimes, it returns an error stating that it couldn't get the data and I'm not sure how to fix this.

This is the code I'm using to get the data:

log(`Return maximum of 20 unique queries with pagination`);
        const db: Database = ArangoDB.getDB();
        const databaseQuery: string = `
LET totalNumberOfResults =
LENGTH(
FOR doc IN Questions
    FILTER doc.private == false
    RETURN doc
) 
    
LET previousQueries = (
    FOR doc IN Questions
        FILTER doc.private == false
        SORT doc._key DESC
        LIMIT @skip, 20
        RETURN doc.question
)
    
RETURN {totalNumberOfResults: totalNumberOfResults, previousQueries}
        `;
        const resultCursor = await db.query({query: databaseQuery, bindVars: {
                skip: (page - 1) * 20
            }})

        const result = await resultCursor.next();
        return result;

This is the error in the logs:

2024-10-02T17:08:53.938Z error: User: 172152998169662705 Message: Error occurred while trying to get previous queries Request-Type: GET Path /api/previous-queries?page=1
2024-10-02T17:08:53.938Z error: User: 172152998169662705 Message: err: TypeError: fetch failed Request-Type: GET Path /api/previous-queries?page=1
2024-10-02T17:08:53.938Z error: User: 172152998169662705 Message: err.message: fetch failed Request-Type: GET Path /api/previous-queries?page=1
2024-10-02T17:08:53.938Z error: User: 172152998169662705 Message: err.stack: TypeError: fetch failed
    at Object.fetch (node:internal/deps/undici/undici:11413:11)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at Array.request (file:///abc/.output/server/node_modules/arangojs/esm/lib/request.js:69:25)
    at Connection._runQueue (file:///abc/.output/server/node_modules/arangojs/esm/connection.js:176:25)
    at Connection.request (file:///abc/.output/server/node_modules/arangojs/esm/connection.js:442:16)
    at Database.request (file:///abc/.output/server/node_modules/arangojs/esm/database.js:256:33)
    at Database.query (file:///abc/.output/server/node_modules/arangojs/esm/database.js:1532:21)
    at Object.handler (file:///abc/server/api/previous-queries.get.ts:38:1)
    at Object.handler (file:///abc/.output/server/chunks/runtime.mjs:2919:24)
    at Object.handler (file:///abc/.output/server/chunks/runtime.mjs:3228:34)
    at Object.handler (file:///abc/.output/server/chunks/runtime.mjs:2990:31)
    at processTicksAndRejections (node:internal/process/task_queues:95:5) Request-Type: GET Path /api/previous-queries?page=1
2024-10-02T17:08:53.939Z error: User: 172152998169662705 Message: err.status: undefined Request-Type: GET Path /api/previous-queries?page=1
2024-10-02T17:08:53.939Z error: User: 172152998169662705 Message: err: {
 "error": true
} Request-Type: GET Path /api/previous-queries?page=1
2024-10-02T17:08:53.939Z error: User: 172152998169662705 Message: err.parsedBody: undefined Request-Type: GET Path /api/previous-queries?page=1

My understanding is that there was a network error. But it happens so often. Not all the time but a lot of the time.

Nginx's error logs is empty (On the database server) Here are a few lines at the end of the Nginx's access logs: (On the database server)

myIpAddress - someUser [02/Oct/2024:17:01:39 +0000] "POST /_db/Some_Collection/_api/cursor HTTP/1.1" 201 1240 "-" "undici"
myIpAddress - someUser [02/Oct/2024:17:01:39 +0000] "POST /_db/Some_Collection/_api/cursor HTTP/1.1" 201 544 "-" "undici"
myIpAddress - someUser [02/Oct/2024:17:01:39 +0000] "POST /_db/Some_Collection/_api/cursor HTTP/1.1" 201 387 "-" "undici"
myIpAddress - someUser [02/Oct/2024:17:01:40 +0000] "POST /_db/Some_Collection/_api/cursor HTTP/1.1" 201 386 "-" "undici"
myIpAddress - someUser [02/Oct/2024:17:01:40 +0000] "POST /_db/Some_Collection/_api/transaction/begin HTTP/1.1" 201 72 "-" "undici"
myIpAddress - someUser [02/Oct/2024:17:01:40 +0000] "POST /_db/Some_Collection/_api/cursor HTTP/1.1" 201 520 "-" "undici"
myIpAddress - someUser [02/Oct/2024:17:01:40 +0000] "POST /_db/Some_Collection/_api/cursor HTTP/1.1" 201 386 "-" "undici"
myIpAddress - someUser [02/Oct/2024:17:01:40 +0000] "PUT /_db/Some_Collection/_api/transaction/35467937 HTTP/1.1" 200 74 "-" "undici"
myIpAddress - someUser [02/Oct/2024:17:01:55 +0000] "GET /_db/_system/_api/database HTTP/1.1" 200 259 "-" "undici"
myIpAddress - someUser [02/Oct/2024:17:01:55 +0000] "GET /_db/Some_Collection/_api/analyzer HTTP/1.1" 200 2952 "-" "undici"
myIpAddress - someUser [02/Oct/2024:17:01:55 +0000] "POST /_db/Some_Collection/_api/analyzer HTTP/1.1" 200 158 "-" "undici"
myIpAddress - someUser [02/Oct/2024:17:01:55 +0000] "POST /_db/Some_Collection/_api/analyzer HTTP/1.1" 200 338 "-" "undici"
myIpAddress - someUser [02/Oct/2024:17:01:55 +0000] "POST /_db/Some_Collection/_api/analyzer HTTP/1.1" 200 337 "-" "undici"
myIpAddress - someUser [02/Oct/2024:17:01:56 +0000] "GET /_db/Some_Collection/_api/collection/CLIENT_DEVICES HTTP/1.1" 200 144 "-" "undici"
myIpAddress - someUser [02/Oct/2024:17:01:56 +0000] "GET /_db/Some_Collection/_api/collection/CLIENT_DEVICES/properties HTTP/1.1" 200 682 "-" "undici"
myIpAddress - someUser [02/Oct/2024:17:01:56 +0000] "POST /_db/Some_Collection/_api/cursor HTTP/1.1" 201 499 "-" "undici"
myIpAddress - someUser [02/Oct/2024:17:01:56 +0000] "GET /_db/Some_Collection/_api/collection/Questions HTTP/1.1" 200 141 "-" "undici"
myIpAddress - someUser [02/Oct/2024:17:01:56 +0000] "GET /_db/Some_Collection/_api/collection/LastQuestion HTTP/1.1" 200 144 "-" "undici"
myIpAddress - someUser [02/Oct/2024:17:01:56 +0000] "GET /_db/Some_Collection/_api/collection/IpAddressesV2 HTTP/1.1" 200 145 "-" "undici"
myIpAddress - someUser [02/Oct/2024:17:01:56 +0000] "GET /_db/Some_Collection/_api/collection/QuestionAnswers HTTP/1.1" 200 147 "-" "undici"
myIpAddress - someUser [02/Oct/2024:17:01:56 +0000] "GET /_db/Some_Collection/_api/collection/Questions/properties HTTP/1.1" 200 706 "-" "undici"
myIpAddress - someUser [02/Oct/2024:17:01:56 +0000] "GET /_db/Some_Collection/_api/collection/IpAddresses HTTP/1.1" 200 143 "-" "undici"
myIpAddress - someUser [02/Oct/2024:17:01:56 +0000] "GET /_db/Some_Collection/_api/collection/LastQuestion/properties HTTP/1.1" 200 616 "-" "undici"
myIpAddress - someUser [02/Oct/2024:17:01:56 +0000] "GET /_db/Some_Collection/_api/collection/IpAddressesV2/properties HTTP/1.1" 200 935 "-" "undici"
myIpAddress - someUser [02/Oct/2024:17:01:56 +0000] "GET /_db/Some_Collection/_api/collection/QuestionAnswers/properties HTTP/1.1" 200 695 "-" "undici"
myIpAddress - someUser [02/Oct/2024:17:01:56 +0000] "POST /_db/Some_Collection/_api/index?collection=Questions HTTP/1.1" 200 269 "-" "undici"
myIpAddress - someUser [02/Oct/2024:17:01:56 +0000] "POST /_db/Some_Collection/_api/index?collection=Questions HTTP/1.1" 200 260 "-" "undici"
myIpAddress - someUser [02/Oct/2024:17:01:56 +0000] "POST /_db/Some_Collection/_api/index?collection=Questions HTTP/1.1" 200 280 "-" "undici"
myIpAddress - someUser [02/Oct/2024:17:01:56 +0000] "GET /_db/Some_Collection/_api/collection/IpAddresses/properties HTTP/1.1" 200 775 "-" "undici"
myIpAddress - someUser [02/Oct/2024:17:01:56 +0000] "POST /_db/Some_Collection/_api/index?collection=IpAddressesV2 HTTP/1.1" 200 265 "-" "undici"
myIpAddress - someUser [02/Oct/2024:17:01:56 +0000] "POST /_db/Some_Collection/_api/index?collection=QuestionAnswers HTTP/1.1" 200 286 "-" "undici"
myIpAddress - someUser [02/Oct/2024:17:01:56 +0000] "POST /_db/Some_Collection/_api/index?collection=QuestionAnswers HTTP/1.1" 200 288 "-" "undici"
myIpAddress - someUser [02/Oct/2024:17:01:56 +0000] "POST /_db/Some_Collection/_api/index?collection=IpAddresses HTTP/1.1" 200 263 "-" "undici"
myIpAddress - someUser [02/Oct/2024:17:02:04 +0000] "POST /_db/Some_Collection/_api/cursor HTTP/1.1" 201 742 "-" "undici"
myIpAddress - someUser [02/Oct/2024:17:02:04 +0000] "POST /_db/Some_Collection/_api/cursor HTTP/1.1" 201 1222 "-" "undici"
myIpAddress - someUser [02/Oct/2024:17:02:44 +0000] "POST /_db/Some_Collection/_api/cursor HTTP/1.1" 201 742 "-" "undici"
myIpAddress - someUser [02/Oct/2024:17:04:53 +0000] "POST /_db/Some_Collection/_api/cursor HTTP/1.1" 201 1221 "-" "undici"
myIpAddress - someUser [02/Oct/2024:17:10:14 +0000] "POST /_db/Some_Collection/_api/cursor HTTP/1.1" 201 623 "-" "undici"
myIpAddress - someUser [02/Oct/2024:17:18:07 +0000] "POST /_db/Some_Collection/_api/cursor HTTP/1.1" 201 485 "-" "undici"
myIpAddress - someUser [02/Oct/2024:17:27:36 +0000] "POST /_db/Some_Collection/_api/cursor HTTP/1.1" 201 386 "-" "undici"
myIpAddress - someUser [02/Oct/2024:17:27:36 +0000] "POST /_db/Some_Collection/_api/cursor HTTP/1.1" 201 544 "-" "undici"
myIpAddress - someUser [02/Oct/2024:17:27:36 +0000] "POST /_db/Some_Collection/_api/cursor HTTP/1.1" 201 387 "-" "undici"

All the requests that reached my server returned a successful status code. Also, my Arangodb logs on the database server don't show any errors.

How do I ensure that the logical server doesn't fail to connect to the database server?

Upvotes: 0

Views: 27

Answers (0)

Related Questions