Separate read/write timeouts for socket operations (original) (raw)
mgo has a single single timeout for read/write operations causes issues when setting sensible limits:
- Setting an (excessive) write limit of 10 seconds means all queries must return in 10 seconds or the
read()times out - effectively makingTimeouta query execution timeout. - A timeout of 1 minute (time for the queries to complete) means calling
write()on an unresponsive socket blocks the caller for 1 minute while the socket times out.
There's some interesting interplay between timeouts too:
- The DialInfo.Timeout is not used when dialing connections, but a custom dialer can be passed to bound the dial time.
- The
mongoSocket.timeout, set indirectly byDialInfo.Timeout- used as a network operation timeout (read/write). - The
session.syncTimeoutwhich bounds the amount of time spent synching the cluster state when acquiring a new session, defaults to 60s. - The
session.sockTimeoutwhich is used assocket.timeoutfor connections spawned by calling a operation when the pool is empty, defaults to 60s. - The
mongoCluster.syncServer()which is hard coded to 5 seconds (syncSocketTimeoutincluster.go) and used to dial a connection if the pool is empty, creating a socket in the pool with asocket.timeoutof 5 seconds. - The hard coded timeout of 10 seconds when performing a
isMaster()cluster call, results in socket in the pool withsocket.timeoutof 10 seconds.
This doesn't include the pool connection wait timeout (session.poolTimeout) or the iter/changestream timeouts, etc.
This ticket is to track fixing the two hard-coded timeouts, and splitting Timeout into ReadTimeout and WriteTimeout in a backwards compatible way.
