Skip to content
Back

Function execution timeout do not respect the seconds i set (BUG)

  • 0
  • Self Hosted
  • Functions
rbiut
20 Mar, 2024, 19:02

Hello again, i open this new post because the other posts about execution timeout are about functions that sometimes freezes and throw the execution timeout error.

While my error is the same error, is not the same behavior, my problem is that the time i set on the timeout is not applied if i set more than 30 secs.. It is suppose that Maximum value is 900 secs, but, if the executions exceed more than 30 secs it fails and do not matter if i set timeout of 40,60,120 secs, it always fails at 30secs

A simple test is with php function and put a sleep(40) and set execution timeout to 120 secs, it will always fails at 30 secs

Im on AppWrite 1.5.13 self-Hosted

TL;DR
Developers are facing a bug where the function execution timeout does not respect the seconds they set. The issue occurs when the function is executed from the web SDK and exceeds 30 seconds, despite setting timeouts above that. Check if the attribute status is available and ensure all attributes are populated before creating documents successfully. The error "Unknown attribute" arises randomly during document creation. To improve efficiency, create collections and non-relationship attributes concurrently. Synchronous execution has a 30-second limit, even if a longer timeout is set. Consider the limitations of AppWrite 1.5.13 self-hosted when faced with execution timeouts.
Steven
27 Mar, 2024, 01:51

Why does this need to be synchronous?

rbiut
27 Mar, 2024, 01:52

because there is no way to create atributes when creating a collection, also, some created documents needs ids of created collections or other documents, they need to create everything in specific order

Steven
27 Mar, 2024, 01:54

I don't really advise creating collections at runtime like this. Especially trying to do it synchronously. There are other occasions where the creation can take longer than 30 seconds like if you had a high load

Steven
27 Mar, 2024, 01:55

Also, are you creating everything one by one serially? If so, that's inefficient

rbiut
27 Mar, 2024, 02:15

what did you suggest?

Steven
27 Mar, 2024, 02:16

Why do you need to create collections at runtime? What's your database design?

Steven
27 Mar, 2024, 02:17

As for this.. create things concurrently when possible. For example, you can create all collections and all non-relationship attributes concurrently

rbiut
27 Mar, 2024, 02:31

actually not, you need to create first all collections, then all non-rel attributes but you need to wait the creation of all collections to proceed to the attributes, then create rel-attributes, then create documents, then bucket then documents updates, so only some part would be async but others needs to be one by one, idk if this help to reduce time, i will try to do that

rbiut
27 Mar, 2024, 02:33

but to do that i will need another runtime, not php

Steven
27 Mar, 2024, 02:33

Yes, of course, you can't do everything concurrently...that's why I said do it concurrently when possible

Steven
27 Mar, 2024, 02:34

You could try using swoole...but, yes, a different runtime would be better

rbiut
27 Mar, 2024, 02:57

Thanks Steven

rbiut
27 Mar, 2024, 14:57

What is the swoole website ? There are too many swoole projects 😣😣

Evdog
27 Mar, 2024, 23:17
rbiut
28 Mar, 2024, 00:51

I decided to re-write my function using nodejs, but how do you handle the creation of 100+ attributes? this is what i have:

TypeScript
     const newdatabase = await databases.create(ID.unique(),name);
     if(newdatabase && newdatabase.$id){
          //Database created, now start creation of collections
          const colloneprom = databases.createCollection(newdatabase.$id,'one','one',perms);
          const colltwoprom = databases.createCollection(newdatabase.$id,'two','two',perms);
          const collthreeprom = databases.createCollection(newdatabase.$id,'three','three',perms);
          const collfourprom = databases.createCollection(newdatabase.$id,'four','four',perms);
          Promise.all([colloneprom,colltwoprom,collthreeprom,collfourprom])
              .then(([collone,colltwo,collthree,collfour]) =>{
                     //All collections are created, now add all attributes```
Do i need to create a const for each attribute and then another Promise.all so we can continue with the next step (create documents)?

`const attributeonecollone = databases.createStringAttribute(newdatabase.$id,collone.$id,'name',100, true);`

Or how to handle the creation of all attributes to then create documents?
rbiut
28 Mar, 2024, 17:26

I ended with something like this using nodejs; all collections, all attributes (simple and relationship attributes), and bucket are created in matter of seconds now, but i have two issues:

  1. The creation of the documents always fails, they fails with error: Unknown attribute: "xxxx" where "xxxx" is random every time i execute the function, also is random the creation of the document that fails, my guess is that attributes are not populated¿? or they are not immediately recognized by appwrite? checking console, the database, collections and all attributes exists
  2. Permissions are only set to 'admin' not to the 2nd user that the permss variable has
rbiut
28 Mar, 2024, 17:28
rbiut
28 Mar, 2024, 20:28

For test purposes, im listing the attributes on the collections that i want to create docs before create the documents:

log(collone: ${JSON.stringify(await databases.listAttributes(newdatabase.$id,'collone'),null,2)}); log(colltwo: ${JSON.stringify(await databases.listAttributes(newdatabase.$id,'colltwo'),null,2)}); log(collthree: ${JSON.stringify(await databases.listAttributes(newdatabase.$id,'collthree'),null,2)}); Log shows all the attributes correctly, but then it try to create the cocuments, and it still failled with the Error:

Invalid document structure: Unknown attribute: "xxxx" (xxxx is random)

So, i can confirm that attributes are there before create the document, but createDocument fails for unknown attribute error...

rbiut
28 Mar, 2024, 23:39

IDK if this help, but this is AppWrite container log:

TypeScript
[Error] Method: POST
[Error] URL: /v1/databases/:databaseId/collections/:collectionId/documents
[Error] Type: Appwrite\Extend\Exception
[Error] Message: Invalid document structure: Unknown attribute: "name"
[Error] File: /usr/src/code/app/controllers/api/databases.php
[Error] Line: 2918
[Error] Timestamp: 2024-03-28T23:33:44+00:00
[Error] Method: POST
[Error] URL: /v1/databases/:databaseId/collections/:collectionId/documents
[Error] Type: Appwrite\Extend\Exception
[Error] Message: Invalid document structure: Unknown attribute: "name"
[Error] File: /usr/src/code/app/controllers/api/databases.php
[Error] Line: 2918```
rbiut
29 Mar, 2024, 01:39

I confirm my theory about that the attributes are not populated or are not immediately recognized by appwrite and/or createDocument(), i have been execute my function multiple times to see what happens, and as i see in past, the Unknown attribute changes, but, sometimes one or two of the documents are created without problems, listAttributes() returns all the attributes 100% of the time, and createDocument() is executed after the listAttributes() so, createDocument() should not fail with the Unknown attribute error, but it fails...

Steven
29 Mar, 2024, 14:13

Did you check the status of the attribute to make sure they're available and not processing?

rbiut
29 Mar, 2024, 14:25

Yes, i make a call to listattributes before

rbiut
29 Mar, 2024, 14:25

.

rbiut
29 Mar, 2024, 20:29

Ok, i ended creating a new function:

TypeScript
    let attributeStatus;
    while (true) {
        const allatt = await databases.listAttributes(db, col);
        const attribute = allatt.attributes.find(attr => attr.key === att);
        if (attribute) {
            attributeStatus = attribute.status;
            if (attributeStatus === 'available') {
                break;
            }
        }
        // Wait for a certain amount of time before checking again
        await new Promise(resolve => setTimeout(resolve, 1000)); // Adjust the delay as needed
    }
    log(`The attribute "${att}" of collection "${col}" is available now!`);
  }```

and called it before create the documents and indexed, i call it only for needed attributes (17):

`waitforatt(newdatabase.$id, 'collone', 'name');`

now it works, it creates everything... but, only if i execute it from console, if i execute it from web sdk, it fails if it pass the 30secs, so at the end i have the same problem as the php... 😩 it dont respect the timeout i set on console, it breaks at 30secs exactly
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