-
Notifications
You must be signed in to change notification settings - Fork 71
Description
I'm making calls to Fauna from a Netlify function, and I seem to be getting a lot of timeout errors that I can't get rid of. They occur to ~10% or more of my calls, but without a particular pattern that I see.
{"message":"Request aborted due to timeout","isTimeoutError":true} Response with status 500 in 5006 ms.
const formattedResponse = require('./utils/formattedResponse')
const {encodeString} = require("./utils/encodeDecodeString")
const faunadb = require('faunadb')
const secret = process.env.DB_ADMIN_KEY
const faunaClient = new faunadb.Client({ secret, timeout: 5, queryTimeout: 5000, keepAlive: true })
const q = faunadb.query
const handler = async (event, context, callback) => {
if(event.httpMethod !== 'POST') {
return formattedResponse(405, { message: 'Method not supported. POST expected.' })
}
const { client, uid } = JSON.parse(event.body)
if(!uid || !client) {
return formattedResponse(500, { message: 'Insufficient data provided.' })
}
try {
const PARAMETERS = await faunaClient.query( <FAUNA QUERY EXCLUDED> )
return formattedResponse(200, {
client: PARAMETERS.client,
parameters: PARAMETERS.parameters,
db: encodeString(PARAMETERS.db.id)
})
} catch (error) {
console.log(JSON.stringify(error))
if(error.requestResult) return formattedResponse(error.requestResult.statusCode, { message: error.message })
return formattedResponse(500, { message: 'Something went wrong.' })
}
}
module.exports = {
handler
}
I've tried adding context.callbackWaitsForEmptyEventLoop = false
and looked at https://docs.fauna.com/fauna/current/drivers/known_issues. I've tried changing the keepAlive setting to false to see if that changed anything, but I keep getting timeout errors.
I'm running the latest version "faunadb": "^4.1.1" and using the latest version of Netlify CLI.
Am I doing something wrong? Or is this to be expected and should I find a way to retry in case of a timeout?