-
Notifications
You must be signed in to change notification settings - Fork 70
Description
Hi 👋
I'm encountering a TLS-related issue when using mongodb+srv:// URIs in combination with ssl=false / tls=false to disable TLS. While the first MongoDB connection works, connections in the pool fail with:
ssl connect: Invalid TLS option: {cacerts,nil} - {:options, {:cacerts, nil}}
🔍 What’s happening
I'm using this connection URL from the environment:
export DB_URL_STATS="mongodb+srv://user:[email protected]/dbname?...&ssl=false&tls=false"
My code to initialize MongoDB (via a GenServer on app startup):
Mongo.start_link(
url: mongo_srv_url,
name: :stats_mongo,
pool_size: 5,
timeout: 60_000,
checkout_timeout: 60_000,
pool_timeout: 5_000,
ssl: false,
tls: false,
ssl_opts: [verify: :verify_none, cacerts: nil]
)
❌ What doesn't work
In app startup, I get this in logs:
Successfully connected to MongoDB with connection pool
ssl connect: Invalid TLS option: {cacerts,nil} - {:options, {:cacerts, nil}}
So looks like first connection was done successfully (Successfully connected to MongoDB with connection pool
) and later it crashes for rest?
When I don't pass ssl_opts
it fails with:
15:32:13.421 [error] Mongo.MongoDBConnection (#PID<0.1197.0>) failed to connect: ** (Mongo.Error) ....svc.cluster.local:27017 ssl connect: Options (or their values) can not be combined: [{verify,verify_peer},
{cacerts,undefined}] - {:options, :incompatible, [verify: :verify_peer, cacerts: :undefined]}
This repeats for each pooled connection after the first.
✅ Expected behavior
If ssl=false or tls=false is passed via connection string or options, no TLS should be attempted
At minimum, {cacerts, nil} should not be passed to :ssl.connect/3