Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting timeout errors a lot #494

Closed
fabianhijlkema opened this issue May 14, 2021 · 4 comments
Closed

Getting timeout errors a lot #494

fabianhijlkema opened this issue May 14, 2021 · 4 comments

Comments

@fabianhijlkema
Copy link

fabianhijlkema commented May 14, 2021

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?

@github-actions
Copy link

Internal ticket number is OSS-724

@fireridlle
Copy link
Contributor

you pass queryTimeout to the Client constructor which is set to be 5 sec

@fabianhijlkema
Copy link
Author

I know, if I set it 10 seconds it times out at 10. Which is the maximum amount of seconds a Netlify Function will run. But usually this call takes a fraction of a second.

But maybe the problem lies in the local dev server run by Netlify, because on a live Netlify function this seems to happen less or not. So I might need to raise this issue with Netlify rather than here.

@fireridlle
Copy link
Contributor

fireridlle commented May 14, 2021

Can you check the NodeJS runtime version? there is an issue with some 12.16.1 version (probably some other versions too)
Long story short, NodeJS v12.16.1 doesn’t trigger the end event for Http2Stream. you can read more here nodejs/node#31309.

Personally, I have got the same when using NodeJS v12.16.1 on and of.
With lts/erbium → v12.22.1 issue seems to be fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants