In pgjdbc we have:
loginTimeoutconnectTimeoutsocketTimeoutcancelSignalTimeout
But it isn't clear to me what's the difference (when are they applied) between loginTimeout, connectTimeout and socketTimeout.
In pgjdbc we have:
loginTimeoutconnectTimeoutsocketTimeoutcancelSignalTimeoutBut it isn't clear to me what's the difference (when are they applied) between loginTimeout, connectTimeout and socketTimeout.
On
After reading the source, I'd say it is like this:
connectTimeout specifies how long to wait for a TCP network connection to get established
loginTimeout specifies how long the whole process of logging into the database is allowed to take
socketTimeout specifies how long the client will wait for a response to a command from the server before throwing an error
The first two are related to establishing a connection, the third is relevant for the whole database session.
Establishing a TCP connection is part of establishing a database connection.
As documented in the PostgreSQL JDBC documentation:
The
connectTimeoutandsocketTimeoutare timeouts on low-level socket operations. TheconnectTimeoutgoverns the time needed to establish a TCP socket connection. Establishing a TCP connection doesn't guarantee a login (it doesn't even guarantee that you're connecting to a PostgreSQL server, just that you connected to something that accepted your TCP connection). AsocketTimeoutgoverns the time a socket can be blocked waiting to read from a socket. This involves all reads from the server, not just during connect, but also during subsequent interaction with the server (eg executing queries).On the other hand
loginTimeoutgoverns the PostgreSQL protocol operation of connecting and authenticating to the PostgreSQL server. This involves establishing a TCP connection followed by one or more exchanges of packets for the handshake and authentication to the PostgreSQL server (I'm not familiar with the details of the PostgreSQL protocol, so I can't be very specific).Exchanging these packets can take additional time, or if you connected to something that isn't a PostgreSQL server the packet exchange may stall. It might be possible to solve this with careful control of both
connectTimeoutandsocketTimeout, but there are no guarantees (eg data is being exchanged, but the login never completes). In addition, as thesocketTimeoutalso governs all other operations on the connection, you may want to set it higher (eg for other operations that take a long time to get a response back) than you are willing to wait for the login to complete.The
cancelSignalTimeoutis used as the connect and socket timeout of the separate TCP connection used for cancel commands.