-
Notifications
You must be signed in to change notification settings - Fork 325
Description
Example 1:
Supposed I have
// at index.js
let sql = Postgres({ max: process.env.PGMAXCONNECTIONS });and PGMAXCONNECTIONS is set as
PGMAXCONNECTIONS=20 node index.jsThen we don't get 20 connections as expected, but only 1! The problem is that options.max will be the string "20" instead of the number 20, so the logic to create the array of connections won't work:
const connections = [...Array(options.max)].map(...)Example 2:
This kind of issue might also happen with the idle_timeout, max_lifetime or connect_timeout options. They end up being used in the timer utility, in connection.js (which calls setTimeout). A numeric string will work well because setTimeout will coerce the string to a number. However suppose there is some typo like this:
# notice the comma after 5
PGIDLE_TIMEOUT=60, node indexWhen the numeric string can't be coerced to a number, setTimeout will still work but using 0 instead! This will obviously cause unexpected behaviors. In this case we would never see any idle connections when inspecting pg_stat_activity.
There might be other options where this sort of problems happen, I didn't check all of them.
Overall I think this kind of issues could be easily catched if some simple validations were done when parsing the options.
Thanks.