Site name: bcup-members.netlify.app
Hi,
I have a problem with a Netlify function which runs into a timeout, but I don’t know why. From the other functions I have tested in my app so far, this is the only one which runs into a timeout.
Because of that timeout I added logging statements to that function to see the timestamps when the function is at what point in the code. As follows is the log of one call. As seen all logging statements including the last occur in the same second the function get invoked.
And then 10 seconds after the last log the timeout log comes.
7:30:48 PM: e68fd74c INFO [request] /api/member/card
7:30:48 PM: e68fd74c INFO user: auth0|5ee294........
7:30:48 PM: e68fd74c INFO member id: 29431890......
7:30:48 PM: e68fd74c INFO before fauna request
7:30:48 PM: e68fd74c INFO after fauna request
7:30:48 PM: e68fd74c INFO id 1617811......
7:30:48 PM: e68fd74c INFO member {
firstname: 'yxyxyxyyx',
lastname: 'yxyxyyyxyx',
email: 'yxyxyxyx@yxyxyxy.yyx',
joinedDate: '2009-05-21T00:00:00.000Z',
registered: false,
invited: true
}
7:30:58 PM: e68fd74c Duration: 10010.55 ms Memory Usage: 46 MB
7:30:58 PM: e68fd74c ERROR Task timed out after 10.01 seconds
As follows is my function code in Typescript. As you can see right after the last logging statement there is only one call left to return the respone res.status(200).json(member);
I have no idea what could possibly be wrong here. That function runs flawlessly on localhost in <1 second.
import { getSession, withApiAuthRequired } from '@auth0/nextjs-auth0';
import { query } from 'faunadb';
import { IUserProfile } from '@utilities/auth0/types';
import { faunaApiClient } from '@utilities/fauna/faunaClient';
import { IClubMember } from '@utilities/types/club';
type IFaunaClubMember = IClubMember & {
joinedDate: {
date: Date;
};
};
export default withApiAuthRequired(async function card(req, res) {
const { user } = getSession(req, res);
// LOGGING - START
console.log('user: ', user.sub);
console.log(
'member id: ',
(user as IUserProfile).app_metadata.club_member_id
);
// LOGGING - END
try {
// LOGGING - START
console.log('before fauna request');
// LOGGING - END
const response = await faunaApiClient.query<{
ts: number;
data: IFaunaClubMember;
}>(
query.Get(
query.Ref(
query.Collection('ClubMember'),
(user as IUserProfile).app_metadata.club_member_id
)
)
);
// LOGGING - START
console.log('after fauna request');
console.log('id', response.ts);
// LOGGING - END
const member = {
...response.data,
joinedDate: response.data.joinedDate.date.toISOString(),
};
// LOGGING - START
console.log('member', member);
// LOGGING - END
res.status(200).json(member);
} catch (error) {
console.error(error);
res.status(error.status || 500).json({
code: error.code,
error: error.message,
});
}
});
I hope somebody has a clue what’s wrong here or what I’m missing.
Best regards,
tpinne