Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MongoDB Java driver: autoConnectRetry

Our current connection configuration looks like this:

MongoClientOptions.builder()
    .autoConnectRetry(true).maxAutoConnectRetryTime(1200000)
    .socketTimeout(30000).connectTimeout(15000).build();
     // SocketTimeout: 30s, ConnectionTimeout 15s, ReconnectRetry: 20min

autoConnectRetry and maxAutoConnectRetryTime are deprecated in the current version (source code) and will be removed: "There is no replacement for this method. Use the connectTimeout property to control connection timeout."

I thought retries and connection timeouts were two different things. Does anyone know why this was changed and what (internal) implications this has?

like image 320
xeraa Avatar asked Apr 25 '14 14:04

xeraa


1 Answers

There was a lot of confusion about the meaning of autoConnectRetry. Most people think it means that, if an operation failed due to an IOException, the driver would retry the operation until maxAutoConnectRetryTime elapsed. But that is not the case.

All it means is that, on calls to Socket.connect(), the driver retries a failed attempt to connect until maxAutoConnectRetryTime elapsed. But this is exactly what connectTimeout is for. The only additional capability of autoConnectRetry is so that you can specify a longer connect timeout than is allowed by the underlying operating system (which typically enforces a max connect timeout that caps the value that the user specifies).

Due to this confusion, the lack of value of the feature, and the fact that none of the other MongoDB drivers support this feature, we decided to deprecate it (and remove it in the next major release).

like image 104
jyemin Avatar answered Oct 25 '22 12:10

jyemin