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:
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
The function call that causes this error looks like this:
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:
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?
try to check the docker logs for the appwrite container for a 500 error
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 .
what's the full error exactly?
[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'
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 (!).
I might have copied half of two entries ... can't tell which line is the first one in the list of errors.
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
Hmmm ... I see ok, thanks.
Why is the error being reported as DELETE if the error is duplicate key?
DELETE is the API call you made. Appwrite does a few things as part of the API call which is throwing an error.
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.
then you might be looking at the wrong error log
Unless you apply rate limits to the SDK with using account JWT
Well, even if I am, the error is reporting a failed DELETE with a UNIQUE ID constraint (!)
yes, i believe rate limits are applied on API calls made using a JWT
the error is regarding a duplicate audit log entry. it's not really related to your document
Ah!
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?
Because perhaps that's what's happening
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)
yes, it should work.
yes, to turn it off, change it to disabled
docs on environment variables can be found here: https://appwrite.io/docs/environment-variables#general
Ok, thanks again.
Recommended threads
- Type Mismatch in AppwriteException
There is a discrepancy in the TypeScript type definitions for AppwriteException. The response property is defined as a string in the type definitions, but in pr...
- What Query's are valid for GetDocument?
Documentation shows that Queries are valid here, but doesn't explain which queries are valid. At first I presumed this to be a bug, but before creating a githu...
- Realtime with multiple connections
I need the Realtime on multiple Collections for diffrent applicational logic. So my question is: Is there a way to have only 1 Websocket connection or do I need...