Open KenLR opened 5 months ago
Hi @KenLR - Thanks for the informative issue. I'm sorry I haven't had time to respond, if this is correct, that is quite serious! I'm unfortunately very pressed for time, so I don't know when I can dig into it, but if you have any new information, do post it here!
Hi everyone! I've encountered an intermittent and unexpected behaviour with postgres.js.
Summary
The result from postgres.js queries occasionally contains
undefined
values. The result in such cases would look like:[{ id: 1 }, { id: 2 }, undefined]
It's not clear to me if this is an expected behaviour and, if so, under what circumstances it occurs.
This unexpected behaviour leads to errors like:
Cannot read properties of undefined (reading 'id')
as until recently, our results were always predictable: we'd receive either an empty or non-sparse array as a result.Details
The issue appears sporadically and doesn't seem to correlate directly with any specific type of query. However, we've observed increased Postgres latency, with some queries timing out around the same period. It's unclear if these timeouts are somehow related to this behaviour; the frequency of timeouts is much higher compared to the
undefined
values.I am unable to reproduce the issue locally; we only have production logs showing this occurring a few times a day.
Here is a portion from our codebase:
Workaround
If I apply a filter to the results returned by
exec
, as shown in the example below, it effectively prevents the errors we've been experiencing. This leads me to believe that theundefined
values are indeed originating from postgres.js, rather than from other parts of our stack.Environment
Happy to provide more details. Any insights or guidance would be greatly appreciated.
Thank you!