Back

Non-specific server error when running multiple queries in parallel

  • 0
  • Self Hosted
  • Databases
makepies
22 Mar, 2023, 16:34

I have a svelte application that has an actions handler (server) that then uses the server SDK, with account JWT to create TWO dependent models.

For performance I want to run these queries in parallel using Promise.all() - however, when I do this, I get a non-specific error that I cannot troubleshoot.

Here is the error:

TypeScript
Error: Server Error
    at Client.call (/Users/darren/Development/svelte/register/node_modules/.pnpm/node-appwrite@8.2.0/node_modules/node-appwrite/lib/client.js:171:31)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Databases.createDocument (/Users/darren/Development/svelte/register/node_modules/.pnpm/node-appwrite@8.2.0/node_modules/node-appwrite/lib/services/databases.js:1055:16)
    at async DatabaseServer.create (/src/services/database/database.js:105:21)
    at async Promise.all (index 1)
    at async create (/src/routes/app/events/create/+page.server.js:32:23)
    at async Module.handle_action_json_request (/node_modules/.pnpm/@sveltejs+kit@1.13.0_svelte@3.57.0+vite@4.0.0/node_modules/@sveltejs/kit/src/runtime/server/page/actions.js:48:16)
    at async resolve (/node_modules/.pnpm/@sveltejs+kit@1.13.0_svelte@3.57.0+vite@4.0.0/node_modules/@sveltejs/kit/src/runtime/server/respond.js:369:17)
    at async Module.respond (/node_modules/.pnpm/@sveltejs+kit@1.13.0_svelte@3.57.0+vite@4.0.0/node_modules/@sveltejs/kit/src/runtime/server/respond.js:240:20)
    at async file:///Users/darren/Development/svelte/register/node_modules/.pnpm/@sveltejs+kit@1.13.0_svelte@3.57.0+vite@4.0.0/node_modules/@sveltejs/kit/src/exports/vite/dev/index.js:505:22
TL;DR
The user is experiencing a non-specific server error when running multiple queries in parallel using the Appwrite server SDK. The error message mentions a "Server Error" without providing any specific details. The user suspects that the error may be related to rate limits or duplicate key constraints. The support team suggests checking the Appwrite documentation for information on environment variables and how to disable rate limits. They also mention a bug related to rate limits that will be fixed in the next version of Appwrite. To troubleshoot the error, they recommend checking the Docker logs for the Appwrite container for a 500 error. The user is also encouraged to provide more specific
makepies
22 Mar, 2023, 16:34

The function call that causes this error looks like this:

TypeScript
const _event = commit({
      request,
      cookies,
      method: 'save',
      model: eventModel,
      data: eventData,
      permissions: []
    })

    const _meta = commit({
      request,
      cookies,
      method: 'save',
      model: metaModel,
      data: metaData,
      permissions: []
    })

    const [ event ] = await Promise.all([ _event, _meta ])

The commit function is a convenience wrapper that results in this AppWrite server SDK call:

TypeScript
  async create (data, permissions) {
    if (!this.config.doc) this.doc(data.$id || data.id)
    data.id = this.config.doc
    this._startRequest()
    this.response = await this.connection.createDocument(this.config.database, this.config.collection, this.config.doc, data, permissions)
    this._endRequest()
    return this.response
  }

... and the this.connection is an instance of new Databases(client)

If I run the queries one after the other, by awaiting the first #commit before running the second, I have no errors. But if I call them both together and use await Promise.all() as shown in the example, this error is thrown?

BTW, the line that throws the error in node-appwrite is shown in the attachment, line 171

How can I diagnose this generic error? Is it known that parallel requests to the server using the same JWT throws an error perhaps?

Drake
22 Mar, 2023, 17:15

try to check the docker logs for the appwrite container for a 500 error

makepies
22 Mar, 2023, 21:43

Thanks @Steven - yes I can see the problem in the logs. Duplicate key in the database. Sure would be useful if it relayed those database errors to the console, at least during development ... Thanks though .

Drake
22 Mar, 2023, 21:44

what's the full error exactly?

makepies
22 Mar, 2023, 21:54
TypeScript
[Error] File: /usr/src/code/app/controllers/api/databases.php
[Error] Line: 2418
[Error] Timestamp: 2023-03-22T18:40:08+00:00
[Error] Timestamp: 2023-03-22T18:40:08+00:00
[Error] Method: DELETE
[Error] URL: /v1/databases/:databaseId/collections/:collectionId/documents/:documentId
[Error] Type: Utopia\Database\Exception\Duplicate
[Error] Message: Duplicated document: Duplicate entry 'ip:172.19.0.1,method:DELETE,url:localhost/v1/databases/:datab...' for key 'unique1'
makepies
22 Mar, 2023, 21:56

Interestingly, even with the errors, you can't see the collection or id which are throwing errors ... it's a little like hunting around - it would be a better developer experience if the errors were more readily available. This one cost me about 90 minutes (!).

makepies
22 Mar, 2023, 21:57

I might have copied half of two entries ... can't tell which line is the first one in the list of errors.

Drake
22 Mar, 2023, 21:57

ahh this is a bug related to rate limits: https://github.com/appwrite/appwrite/issues/4642

This should be fixed in the next version of Appwrite.

For now, you can disable rate limits to prevent this error: https://appwrite.io/docs/rate-limits#disable-limits

makepies
22 Mar, 2023, 21:58

Hmmm ... I see ok, thanks.

Why is the error being reported as DELETE if the error is duplicate key?

Drake
22 Mar, 2023, 22:00

DELETE is the API call you made. Appwrite does a few things as part of the API call which is throwing an error.

makepies
22 Mar, 2023, 22:01

No, I didn't. I was using the createDocument method ... BTW as I mentioned, all calls are being made with the node-appwrite server SDK.

Drake
22 Mar, 2023, 22:02

then you might be looking at the wrong error log

makepies
22 Mar, 2023, 22:02

Unless you apply rate limits to the SDK with using account JWT

makepies
22 Mar, 2023, 22:02

Well, even if I am, the error is reporting a failed DELETE with a UNIQUE ID constraint (!)

Drake
22 Mar, 2023, 22:02

yes, i believe rate limits are applied on API calls made using a JWT

Drake
22 Mar, 2023, 22:03

the error is regarding a duplicate audit log entry. it's not really related to your document

makepies
22 Mar, 2023, 22:03

Ah!

makepies
22 Mar, 2023, 22:05

Let me ask you though - if I try to simultaneously create two different documents in parellel as I described above, rate limits not withstanding, they should be permitted, correct? I'm not going to clash with your audits reporting something twice and failing and therefore blocking my queries from going through?

makepies
22 Mar, 2023, 22:06

Because perhaps that's what's happening

makepies
22 Mar, 2023, 22:07

The docs you linked to show the key _APP_OPTIONS_ABUSE. The default value is 'enabled' - it should be string 'disabled' to disable? (No references to possible values in the docs, just want to be sure)

Drake
22 Mar, 2023, 22:09

yes, it should work.

Drake
22 Mar, 2023, 22:09

yes, to turn it off, change it to disabled

Drake
22 Mar, 2023, 22:10

docs on environment variables can be found here: https://appwrite.io/docs/environment-variables#general

makepies
22 Mar, 2023, 22:11

Ok, thanks again.

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more