Mongodb replicaset cluster maximum logicalTime => 2038 year max

Hello,
I have noticed a mongodb bug. If I set my system time to 2070 and I set the mongodb cluster replicaSet configuration, mongod crash:

python3 -c "
> import pymongo
> client = pymongo.MongoClient('mongodb://127.0.0.1:27017')
> config = {'_id': 'rs0', 'members': [{'_id': 0, 'host': '127.0.0.1:27017'}]}
> client.admin.command('replSetInitiate', config)
> "
Traceback (most recent call last):
  File "<string>", line 5, in <module>
  File "/usr/lib/python3/dist-packages/pymongo/database.py", line 740, in command
    codec_options, session=session, **kwargs)
  File "/usr/lib/python3/dist-packages/pymongo/database.py", line 637, in _command
    client=self.__client)
  File "/usr/lib/python3/dist-packages/pymongo/pool.py", line 694, in command
    exhaust_allowed=exhaust_allowed)
  File "/usr/lib/python3/dist-packages/pymongo/network.py", line 162, in command
    parse_write_concern_error=parse_write_concern_error)
  File "/usr/lib/python3/dist-packages/pymongo/helpers.py", line 168, in _check_command_response
    max_wire_version)
pymongo.errors.OperationFailure: cluster time cannot be advanced beyond its maximum value, full error: {'operationTime': Timestamp(0, 0), 'ok': 0.0, 'errmsg': 'cluster time cannot be advanced beyond its maximum value', 'code': 40482, 'codeName': 'Location40482', '$clusterTime': {'clusterTime': Timestamp(0, 0), 'signature': {'hash': b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', 'keyId': 0}}}

From mongo source it seems the max clock value is defined as below

static const uint32_t kMaxSignedInt = ((1U << 31) - 1);
bool lessThanOrEqualToMaxPossibleTime(LogicalTime time, uint64_t nTicks) {
   return time.asTimestamp().getSecs() <= LogicalClock::kMaxSignedInt &&
        time.asTimestamp().getInc() <= (LogicalClock::kMaxSignedInt - nTicks);
}

Which means: 2 ** 31 / (3600 * 24 * 365) == 68 years from 1970 / 1970 + 68 == 2038

  • if I set the year as 2042 → restart → crash
  • if I set the year as 2035 → restart the configuration → it’s correctly working

It seems linked to this bug https://jira.mongodb.org/browse/SERVER-36870, which was raised in 2018. Do you know if there has been any update on this topic ?

Yours sincerely,

Alexis

Hi @Alexis_Doussot,

Welcome to the MongoDB Community Forums… :clap:

This is a known problem for all systems using 32-bit integers for measuring time and as you can see in the JIRA, we’re aware of the issue and the ticket has been assigned to a team’s queue. You can also keep track of further comments right there on the ticket.

Regards,
Kushagra

2 Likes