Getting this error a lot when using the Fauna JS driver:
TimeoutError: Request aborted due to timeout
This timeout error is being returned almost instantly after attempting to create the transaction. My transaction is also actually still being written, but the Fauna JS driver returns this error anyway.
This is annoying, as I have logic that retries the transaction on a driver error. Quite regularly when creating a transaction, a timeout is returned once (sometimes twice) and then it is successful. Resultantly, I’ll end up with 2 or 3 documents instead of 1.
Code:
Fauna.createDecision = async (id, decision) => {
decision = {
id: id,
...decision,
created: Now(),
}
let attempts = 5
const createDecisionRetry = async (decision, attempts) => {
const serverClient = new faunadb.Client({ secret: process.env.FAUNA_KEY_SECRET })
try {
await serverClient.query(
Create(
Collection('decisions'),
{ data: decision }
)
)
} catch (e) {
console.error('Error Fauna.createDecision', e)
if (attempts > 1) {
setTimeout(() => {
createDecisionRetry(decision, attempts - 1)
}, 200)
}
}
}
createDecisionRetry(decision, attempts)
}
I’m calling this function like so in an async function:
await Fauna.createDecision(id, decision)
Environment:
Execute: Lambda
Node version: 12
Fauna driver: 4.2.0
Not sure if this is an error with my code or with the driver?