Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add postgres connection timeout option (typeorm#6160)
There was no documented way of setting a connection timeout for the postgres driver. We recently ran into an issue with our network that caused a container to hang indefinitely attempting to connect to postgres. We managed to resolve the issue by setting 'connectionTimeoutMillis' in the 'extra' field of our connection options. This approach does not appear to be documented anywhere. Seeing that MongoDB and MySQL drivers both support a connection timeout as part of the documented API, we felt it made sense to add a similar option to the Postgres driver and hopefully avoid some headaches down the road. This commit adds a 'connectTimeoutMS' option to the postgres driver that gets translated to the appropriate field for the pg library. It also updates the documentation to reflect this new option. Because the default behavior of the underlying pg library is to attempt to connect indefinitely, we didn't feel like it was a safe change to introduce a default timeout, even if that's more sane behavior. As mentioned earlier, both the MySQL and MongoDB drivers support a connection timeout option. MySQL uses 'connectTimeout' while MongoDB uses 'connectTimeoutMS'. We went with 'connectTimeoutMS' as to not introduce yet another name for a connection timeout, and because the 'MS' suffix makes it clearer what is expected. We hope a future PR may adjust the MySQL connection options to adopt the same name, but will leave that up to someone with a stronger opinion.
- Loading branch information