mirror of
https://github.com/zulip/zulip.git
synced 2025-11-02 13:03:29 +00:00
The libpq client library, used under the hood by psycopg2, supports passing a list of hosts; they are tried sequentially until one of them works[^1]. In cases where this is used, it is often the case that the other servers are read-only hot spare replicas. Since Zulip does not expect to be in a read-only transaction, we require that the server that we connect to be writable, by passing `target_session_attrs`[^2]. To limit how long we may block connecting to a potentially bad host before moving on, we set `connection_timeout` from null (meaning forever) to 2 (the lowest supported value)[^3], so we move on quickly in the case that the server is running but unable to handle new connections. [^1]: https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-MULTIPLE-HOSTS [^2]: https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNECT-TARGET-SESSION-ATTRS [^3]: https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNECT-CONNECT-TIMEOUT