Skip to content

Separate read/write timeouts for socket operations #160

Closed
@domodwyer

Description

@domodwyer

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 making Timeout a 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:

mgo-timeouts

  • 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 by DialInfo.Timeout - used as a network operation timeout (read/write).

  • The session.syncTimeout which bounds the amount of time spent synching the cluster state when acquiring a new session, defaults to 60s.

  • The session.sockTimeout which is used as socket.timeout for connections spawned by calling a operation when the pool is empty, defaults to 60s.

  • The mongoCluster.syncServer() which is hard coded to 5 seconds (syncSocketTimeout in cluster.go) and used to dial a connection if the pool is empty, creating a socket in the pool with a socket.timeout of 5 seconds.

  • The hard coded timeout of 10 seconds when performing a isMaster() cluster call, results in socket in the pool with socket.timeout of 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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions