Back

Operation timed out after 30002 milliseconds with Functions - Completely random

  • 0
  • Self Hosted
  • Functions
_alnes_
27 Apr, 2024, 09:02
  • Appwrite Version 1.5.5 selfhosted
  • Function Runtime Node.js 16.0
  • Timeout 240
  • .env: _APP_FUNCTIONS_TIMEOUT=1900
  • Angular 17

In the Appwrite function I use this admittedly somewhat larger method to create a collection with attributes:

TypeScript
async function newNotesCollection(title, res, log) {
  log('newNotesCollection');
  try {
    const response = await appwriteService.createCollection(title);
    log('after createCollection...');

    await appwriteService.createStringAttribute('message',response.$id, 2000);
    log('after createStringAttribute message...');
    await appwriteService.createStringAttribute('username',response.$id, 50);
    log('after createCollection username...');
    await appwriteService.createStringAttribute('userId',response.$id, 50);
    log('after createCollection userId...');
    await appwriteService.createNumberAttribute('date', response.$id, 50);
    log('after createCollection date...');

    let ready = false;

    while (!ready) {
      log('Attributes not ready....');
      ready = await appwriteService.newCollectionAttributesReady(response.$id,log);
      await delay(2000); // Warte 2 Sekunden, bevor du die Methode erneut aufrufst
    }

    log('Attributes ready.');

    return res.send(response);
  } catch (e) {
    log('Error: ' + e);
    return res.status(500).send('An error occurred: ' + e);
  }
}```

In 9 out of 10 cases everything runs perfectly, the while loop always runs twice and then everything is ready:

But in this one case I get the timeout and NO logs at all:

`Operation timed out after 30002 milliseconds with 0 bytes received with status code 0\nError Code: 0`

- Why does the timeout always come at 30002 milliseconds?
- And why is there a timeout at all.... ?

I've really tried a lot, but unfortunately I can't make any progress at the moment because it's just so random for me.

Thank you for help 🙂
TL;DR
Developers are encountering random timeouts (30002 milliseconds) in their function. They've adjusted their while loop to handle errors if nothing is found. The function runs smoothly most of the time but sometimes results in timeouts and no logs. The CPU and RAM utilization seem fine. The developer is using Appwrite version 1.5.5, self-hosted, with Node.js 16.0 runtime. The timeout is set to 240, but "_APP_FUNCTIONS_TIMEOUT=1900" in .env. The function may be timing out due to delays in attribute creation. It's recommended to troubleshoot the function and look into potential causes
_alnes_
27 Apr, 2024, 09:17

i changed the method a bit (while....): ```js async function newNotesCollection(title, res, log) { log('newNotesCollection'); try { const response = await appwriteService.createCollection(title); log('after createCollection...');

TypeScript
await appwriteService.createStringAttribute('message',response.$id, 2000);
log('after createStringAttribute message...');
await appwriteService.createStringAttribute('username',response.$id, 50);
log('after createCollection username...');
await appwriteService.createStringAttribute('userId',response.$id, 50);
log('after createCollection userId...');
await appwriteService.createNumberAttribute('date', response.$id, 50);
log('after createCollection date...');

let ready = false;

let attempts = 0;
const maxAttempts = 8;

while (!ready && attempts < maxAttempts) {
  log('Attributes not ready....');
  ready = await appwriteService.newCollectionAttributesReady(response.$id,log);
  await delay(2000); // Warte 2 Sekunden, bevor du die Methode erneut aufrufst
}

if (!ready) {
  log('Attributes not ready....');
  return res.status(500).send('Attributes not ready. Collection id: ' + response.$id);
}

log('Attributes ready.');

return res.send(response);

} catch (e) { log('Error: ' + e); return res.status(500).send('An error occurred: ' + e); } }```

_alnes_
27 Apr, 2024, 09:48

So I think the way I rebuilt the while loop, there shouldn't be a timeout anymore. If nothing is found in the while, an error is sent back.... I have now sent requests 100 times, each with a 10 second delay. The first 30 were processed sensibly, but now the timeouts are increasing... (look the image) Server(CPU-Core: 4, Ram 6gb): RAM 39% utilization, cpu approx. 67-78% utilization...

_alnes_
27 Apr, 2024, 09:56

Operation timed out after 30002 milliseconds with Functions - Completely random

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