
I have a webhook set up to execute some code on my function. More than hafl of the executions give me this error : Operation timed out after 30000 milliseconds with 0 bytes received with status code 0\nError Code: 0.
I read somewhere that this could be cuz the function executes synchronously but i am using a domain and I dont know how to make the function run async.
The weird thing is that my webhook retrys sending the exact same response 5 times when it gets an error, and sometimes it works. And even when the webhook times out the data in my database is changed.

This is my code :

const client = new Client()
.setEndpoint(process.env.APPWRITE_API_ENDPOINT)
.setProject(process.env.APPWRITE_FUNCTION_PROJECT_ID)
.setKey(process.env.APPWRITE_API_KEY);
if (req.method == "GET") {
return res.empty();
}
const databases = new Databases(client);
const users = new Users(client);
const body = await JSON.parse(req.bodyRaw);
if (body == undefined) {
return res.empty();
}
const entitlementId = body.event.entitlement_ids[0];
const purchasedAtTime = body.event.purchased_at_ms;
const expirationAtTime = body.event.expiration_at_ms;
const userId = body.event.app_user_id;
const type = body.event.type;
const teamMembership = await users.listMemberships(userId);
if (type == "RENEWAL" || type == "INITIAL_PURCHASE") {
const data = {
maxMembers: plans[entitlementId].members,
paymentDate: new Date(purchasedAtTime),
paymentDueDate: new Date(expirationAtTime),
status: "active",
ownerEmail: teamMembership.memberships[0].userEmail,
ownerName: teamMembership.memberships[0].userName,
};
await databases.updateDocument(
"DBID",
"ColledtionID",
teamMembership.memberships[0].teamId,
data
);
return res.empty();
} else if (type == "EXPIRATION") {
await databases.updateDocument(
"DBID",
"CollectionID",
teamMembership.memberships[0].teamId,
{
status: "inactive",
maxMembers: 1,
}
);
return res.empty();
}
};```

FYI, it's best to wrap code in backticks to format a bit nicer. You can use 1 backtick for inline code (https://www.markdownguide.org/basic-syntax/#code) and 3 backticks for multiline code (https://www.markdownguide.org/extended-syntax/#syntax-highlighting.

yes, when you execution a function via the function domain, it is executed synchronously.
The weird thing is that my webhook retrys sending the exact same response 5 times when it gets an error,
What do you mean by this?

btw you don't need to await
JSON.parse()

you're not covering all cases here so there's a chance the function is not returning a response and maybe Appwrite is still waiting for that response

Thanks I fixed the backticks. What i mean is when the webhook gets a failed response it retrys sending the webhook and sometimes it gets a secessful response but sometimes it still fails with the same data being send to the function.

Maybe the provider is making the additional requests. Do you see multiple executions in Appwrite?

yes I do. and even appwrite has some successful executions and sometimes it fails. same data being passed.

if you see additional executions, it means the provider is making additional requests

the i have covered the only two cases that would be send though

maybe you can add some logging to see where it's getting stuck

Ok so revenue cat sends a webhook and it fails so it sends another in like 5 min and it fails again sometimes it is successfull but when it is revenuecat stops sending. I have checked and it does not send any after a successfull response

I had logging and no logs were executed when it failed.

ok so that would explain the multiple requests

This is not the first time i am experiencing this error. Whenever i try to run a function sync it is a 50/50 chance the function executes. When they do they execute in like 1s or less but when they fail they timeout cuz of the 30s. Before i have fixed this by running the functions async. But this time i am running the functions through a domain.

can you share when your executions happen?

i dont understand
Recommended threads
- API preflight request not working on .f...
When I am calling a function on my APP through the domain is failing. Because the preflight request (OPTIONS HTTP request) times out. this only occurs with fu...
- No Headers
Hi I have 2 appwrite functions, one is working fine on localhost, second is not even working on prod with https, i inspected the api call, no headers are being ...
- Cloud Function Deployment crashing
My golang cloud function crashes on deployment and its a bit non-descript. Here is the error message. It says "Document already exists". This is a general probl...
