On January 10, I released a badly broken version of the MongoDB C Driver, libmongoc 1.5.2. For most users, that version could not connect to a server at all! Luckily, in under 24 hours a developer reported the bug, I reverted the mistake and released a fix. Although it was resolved before it did any damage, this is among the most dramatic mistakes I’ve made since I switched from the PyMongo team to libmongoc almost two years ago. My error stemmed from three mistaken assumptions I’ve had ever since I changed projects. What were they?
Here’s how the story began. In December, a libmongoc user named Alexey pointed out a longstanding limitation: it would only resolve hostnames to IPv4 addresses. Even if IPv6 address records existed for a hostname, the driver would not look them up – when it called getaddrinfo on the hostname to do the DNS resolution, it passed
AF_INET as the address family, precluding anything but IPv4. So if you passed the URI
mongodb://example.com, libmongoc resolved “example.com” to an IPv4 address like
220.127.116.11 and tried to connect to it. If the connection timed out, the driver gave up.