Description
Dear Brian and node-postgres
contributors,
first things first: thanks a stack for conceiving and maintaining this excellent module.
While improving our test harness over at CrateDB on behalf of crate/crate-qa#180, we believe we discovered a nasty issue with respect to async/timing of node-postgres
where we humbly want to ask about your assistance.
I've created two concise repros within gists in order to outline what we've discovered. I am sharing those within the downstream issues #2455 and #2456. I hope they will also do their job properly on your end and that they will be good companions on mitigating this issue. While we specifically tested on CrateDB, I believe the problems might also manifest when talking to other PostgreSQL-compatible databases.
As the title says, the problems only happen when using parameterized queries and when using the pure-JS driver variant. When running the code examples on pg-native
by providing the --native
command line option, I have not been able to reproduce them. Also, when not using parameterized expressions by omitting the --parameterized
option, everything works flawlessly.
Due to the intrinsic details about the asynchronous behavior of Node.js, the errors don't happen on every occasion, that's why I added documentation to the repros about how to run them in a reasonably tight loop by using the watch
utility.
Also, for #2455, I've added documentation about how to run the connection through toxiproxy
in order to add a slight amount of latency, which will increase the chance to trigger the situation tremendously. Please note that this does not apply to #2456, where the origin of the flaw is not related to slowness of the client but rather about its speediness.
For running the repros on my workstation, I used pg@8.5.1
and pg-native@3.0.0
on Node.js v14.15.1. While I am not sure on this, things like #2163, #2327 and #2355 might be related.
Thank you for listening so far. We would be really grateful if you could have a look into this.
With kind regards,
Andreas.