Worers outcome: canceled

Hello, I am struggling a bit with my new API made with hono using CF workers. At some random times, for a few minutes, all requests time out and from the worker logs I see that their outcome is cancelled. Once those few minutes are over, everything works perfectly again. It's worth to note that while I'm getting myself the error, I see some successful requests in the logs too, so it may be only the workers in my area or something like that? The API is really simple, all it does is connect to postgres (First I connected to hyperdrive and got the error, and now I connect to the DB directly and still get the error) then returns the value. Any ideas about how to solve it? It seems to occur very regularly across different locations, according to my logs
1 Reply
Relisora
Relisora5w ago
Every route is prone to fail, here the example of one :
app.get('/seasons', async (c) => {
const client = new Client({ connectionString: c.env.SUPABASE_CONNECTION })

try {
await client.connect()
const result = await client.query('SELECT * FROM season_stats ORDER BY season ASC')
c.executionCtx.waitUntil(client.end())
return c.json({ data: result.rows })
} catch (e) {
console.log(e)
c.executionCtx.waitUntil(client.end())
return c.json({ error: JSON.stringify(e) }, { status: 500 })
}
})
app.get('/seasons', async (c) => {
const client = new Client({ connectionString: c.env.SUPABASE_CONNECTION })

try {
await client.connect()
const result = await client.query('SELECT * FROM season_stats ORDER BY season ASC')
c.executionCtx.waitUntil(client.end())
return c.json({ data: result.rows })
} catch (e) {
console.log(e)
c.executionCtx.waitUntil(client.end())
return c.json({ error: JSON.stringify(e) }, { status: 500 })
}
})
And here is an error linked to that route:
{
"EventType": "fetch",
"Outcome": "canceled",
"ScriptName": "api",
"Event": {
"Response": {
"Status": 0
},
"RayID": "87a39891ba82420b",
"Request": {
"Method": "GET",
"URL": "https://api.swarena.gg/general/seasons"
}
},
"DispatchNamespace": "",
"EventTimestampMs": 1714103293720
}
{
"EventType": "fetch",
"Outcome": "canceled",
"ScriptName": "api",
"Event": {
"Response": {
"Status": 0
},
"RayID": "87a39891ba82420b",
"Request": {
"Method": "GET",
"URL": "https://api.swarena.gg/general/seasons"
}
},
"DispatchNamespace": "",
"EventTimestampMs": 1714103293720
}
Note that sometimes the status is 0 and sometimes it's 200 but the Outcome is always canceled Yes sometimes my website doesn't load at all because it's waiting for those requests. On the client side they look like they're timing out Then if I hit refresh it keeps not loading for 1 - 2 minutes, until at some point everything is good again When it happened to me I saw that the requests I was waiting for an answer were the ones that were logged as cancelled from wrangler logs I am getting user reports notifying me that they have the same problem, but I am guessing it's happening locally on their closest edge node, because when it happens to them my website loads just fine. I can only reproduce when it happens to me directly No, I'm connecting to a supabase database without their js sdk (using pg instead) No worries 😄 I tried connecting through hyperdrive but I had the same issue What surprised me was that the "canceled" log appeared immediately. I'm not sure how this logging is done, but I had that log appear before the client call timed out