I have two serverless projects the communicate with each other. This has been working fine until this week where I've noticed a massive spike in Timeout errors.
Debugging and logging through the code I've found that project1 makes the fetch request like so:
console.log('**** fetch');
const response = await fetch(url, options);
console.log('***** fetch worked');
Project2 gets the request and executes. This all works and returns as so:
var response_to_return = { output: integrationResponseJson, status: integrationResponse.status };
context.res = {
headers: { 'Access-Control-Allow-Origin': '*', 'Content-Type': 'application/json' },
status: response_to_return['status'],
body: response_to_return,
};
console.log("***** SUCCESS*****");
Previously I had context.done() at the end of this but I believe it is not needed due to this SO. I have tested with adding:
context.done()
and also with this from SO
context.done = () => {};
The console.log "SUCCESS" is logged out and the response being returned is status 200 and the body is valid. However Project1 throws a Timeout error after the host.json set time.It also only prints out the first "**** fetch" and not the second so it's lingering on the fetch request.(Note time has been reduced to 1min to trigger the error - increasing the limit still causes the same timeout issue)
It is also worth noting that this works sometimes - and at scale about 30% of requests are falling over with a timeout error - not the same requests every time.
Any advice on what I can do to ensure the fetch request works and receives the response correctly would be greatly appreciated. TIA