Failed to unlink socket file: Operation not permitted

I am facing this issue where I am unable to get my mongod started successfully:

This is the error:

{“t”:{“$date”:“2023-01-13T12:33:59.922+05:00”},“s”:“I”,
“c”:“NETWORK”, “id”:4915701, “ctx”:“-”,“msg”:“Initialized wire
specification”,“attr”:{“spec”:{“incomingExternalClient”:{“minWireVersion”:0,“maxWireVersion”:17},“incomingInternalClient”:{“minWireVersion”:0,“maxWireVersion”:17},“outgoing”:{“minWireVersion”:6,“maxWireVersion”:17},“isInternalClient”:true}}}
{“t”:{“$date”:“2023-01-13T12:33:59.922+05:00”},“s”:“I”,
“c”:“CONTROL”, “id”:23285, “ctx”:“-”,“msg”:“Automatically disabling
TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols
‘none’”} {“t”:{“$date”:“2023-01-13T12:33:59.924+05:00”},“s”:“I”,
“c”:“NETWORK”, “id”:4648601, “ctx”:“main”,“msg”:“Implicit TCP
FastOpen unavailable. If TCP FastOpen is required, set
tcpFastOpenServer, tcpFastOpenClient, and tcpFastOpenQueueSize.”}
{“t”:{“$date”:“2023-01-13T12:33:59.925+05:00”},“s”:“I”, “c”:“REPL”,
“id”:5123008, “ctx”:“main”,“msg”:“Successfully registered
PrimaryOnlyService”,“attr”:{“service”:“TenantMigrationDonorService”,“namespace”:“config.tenantMigrationDonors”}}
{“t”:{“$date”:“2023-01-13T12:33:59.925+05:00”},“s”:“I”, “c”:“REPL”,
“id”:5123008, “ctx”:“main”,“msg”:“Successfully registered
PrimaryOnlyService”,“attr”:{“service”:“TenantMigrationRecipientService”,“namespace”:“config.tenantMigrationRecipients”}}
{“t”:{“$date”:“2023-01-13T12:33:59.925+05:00”},“s”:“I”, “c”:“REPL”,
“id”:5123008, “ctx”:“main”,“msg”:“Successfully registered
PrimaryOnlyService”,“attr”:{“service”:“ShardSplitDonorService”,“namespace”:“config.tenantSplitDonors”}}
{“t”:{“$date”:“2023-01-13T12:33:59.925+05:00”},“s”:“I”,
“c”:“CONTROL”, “id”:5945603, “ctx”:“main”,“msg”:“Multi threading
initialized”} {“t”:{“$date”:“2023-01-13T12:33:59.925+05:00”},“s”:“I”,
“c”:“CONTROL”, “id”:4615611, “ctx”:“initandlisten”,“msg”:“MongoDB
starting”,“attr”:{“pid”:24280,“port”:27017,“dbPath”:“/data/db”,“architecture”:“64-bit”,“host”:“ehsan-HP”}}
{“t”:{“$date”:“2023-01-13T12:33:59.925+05:00”},“s”:“I”,
“c”:“CONTROL”, “id”:23403, “ctx”:“initandlisten”,“msg”:“Build
Info”,“attr”:{“buildInfo”:{“version”:“6.0.3”,“gitVersion”:“f803681c3ae19817d31958965850193de067c516”,“openSSLVersion”:“OpenSSL
1.1.1 11 Sep 2018”,“modules”:,“allocator”:“tcmalloc”,“environment”:{“distmod”:“ubuntu1804”,“distarch”:“x86_64”,“target_arch”:“x86_64”}}}}
{“t”:{“$date”:“2023-01-13T12:33:59.925+05:00”},“s”:“I”,
“c”:“CONTROL”, “id”:51765, “ctx”:“initandlisten”,“msg”:“Operating
System”,“attr”:{“os”:{“name”:“Ubuntu”,“version”:“18.04”}}}
{“t”:{“$date”:“2023-01-13T12:33:59.925+05:00”},“s”:“I”,
“c”:“CONTROL”, “id”:21951, “ctx”:“initandlisten”,“msg”:“Options set
by command line”,“attr”:{“options”:{}}}
{“t”:{“$date”:“2023-01-13T12:33:59.926+05:00”},“s”:“E”,
“c”:“NETWORK”, “id”:23024, “ctx”:“initandlisten”,“msg”:“Failed to
unlink socket
file”,“attr”:{“path”:“/tmp/mongodb-27017.sock”,“error”:“Operation not
permitted”}} {“t”:{“$date”:“2023-01-13T12:33:59.926+05:00”},“s”:“F”,
“c”:“ASSERT”, “id”:23091, “ctx”:“initandlisten”,“msg”:“Fatal
assertion”,“attr”:{“msgid”:40486,“file”:“src/mongo/transport/transport_layer_asio.cpp”,“line”:1125}}
{“t”:{“$date”:“2023-01-13T12:33:59.926+05:00”},“s”:“F”, “c”:“ASSERT”,
“id”:23092, “ctx”:“initandlisten”,“msg”:“\n\n***aborting after
fassert() failure\n\n”}

What I have tried so far:

Delete /tmp/mongodb-27017.sock file and then start mongod by doing sudo service mongod start. It didn’t work. The file mongodb-27017.sock created after running this comand has the following permissions:

srwx------ 1 mongodb mongodb 0 January 13 12:49 /tmp/mongodb-27017.sock

These are the permissions of /data/db:

$ ls -la /data/db
total 8
drwxr-xr-x 2 mongodb mongodb 4096 January 13 11:35 .
drwxr-xr-x 3 root    root    4096 January 13 11:35 ..

What is going wrong here? This is my mongod version:

$ mongod --version
db version v6.0.3
Build Info: {
    "version": "6.0.3",
    "gitVersion": "f803681c3ae19817d31958965850193de067c516",
    "openSSLVersion": "OpenSSL 1.1.1  11 Sep 2018",
    "modules": [],
    "allocator": "tcmalloc",
    "environment": {
        "distmod": "ubuntu1804",
        "distarch": "x86_64",
        "target_arch": "x86_64"
    }
}

I am on Ubuntu 18.

EDIT:
Here are the contents of /var/log/auth.log:

Jan 13 13:40:24 ehsan-HP sudo:    ehsan : TTY=pts/7 ; PWD=/home/ehsan ; USER=root ; COMMAND=/usr/sbin/service mongod restart
Jan 13 13:40:24 ehsan-HP sudo: pam_unix(sudo:session): session opened for user root by (uid=0)
Jan 13 13:40:24 ehsan-HP sudo: pam_unix(sudo:session): session closed for user root

Appears to be permissions issue when you try to bring up mongod as different users
How did you start mongod first time?
Most likely you issued just mongod
After removing tmp file try bring up mongod by issuing just mongod
You should not use sudo which will try to create files as root
Please check documentation
If you installed mongod as service you have to use sudo sysctl mongod start

im facing the same isssue

run,

rm -f /tmp/mongodb-27017.sock

or, check the ownership of the above

4 Likes

sudo rm -f /tmp/mongodb-27017.sock
sudo systemctl start mongod
sudo systemctl status mongod → Running

2 Likes

Try it…:+1:
sudo rm -f /tmp/mongodb-27017.sock