Skip to content

Unix domain socket - Error: failed to lookup address information: Name or service not known #686

Closed
@WatakiWatako

Description

@WatakiWatako

Hey,

It looks like it isn't possible to connect to MongoDB using the Rust driver with a Unix domain socket.

This is occurring on Ubuntu 20.04 with MongoDB v5.0.9.

Connection string:

mongodb::options::ClientOptions::parse("mongodb://%2Ftmp%2Fmongodb-27017.sock/?directConnection=true").await

Resulting error:

Server selection timeout: No available servers. Topology: { Type: Single, Servers: [ { Address: %2ftmp%2fmongodb-27017.sock:27017, Type: Unknown, Error: failed to lookup address information: Name or service not known }, ] }

Notice that the address here ends with ":27017".

cargo.toml

mongodb = { version = "2.2.2", features = ["bson-chrono-0_4"] }

/etc/mongod.conf

# network interfaces
net:
  port: 27017
  bindIp: 127.0.0.1

net:
    unixDomainSocket:
        filePermissions: 0777
$ ls -l / | grep tmp
drwxrwxrwt  12 root root  4096 Jun 24 00:39 tmp

$ ls -l /tmp | grep mongodb
srwxrwxrwx 1 mongodb  mongodb     0 Jun 23 19:21 mongodb-27017.sock

The /tmp/mongodb-27017.sock socket file exists and is accessible to all users on the system.

The connection succeeds via the socket using mongosh and it is possible to run commands.

$ mongosh mongodb://%2Ftmp%2Fmongodb-27017.sock
Current Mongosh Log ID:	62b4fe08e27339e39c82d3e4
Connecting to:		mongodb://%2Ftmp%2Fmongodb-27017.sock/?directConnection=true&appName=mongosh+1.5.0
Using MongoDB:		5.0.9
Using Mongosh:		1.5.0

Thank you!

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions