[SERVER-19716] remove socket when exiting because dbpath not found Created: 03/Aug/15  Updated: 27/Oct/22  Resolved: 27/Oct/22

Status: Closed
Project: Core Server
Component/s: Admin
Affects Version/s: 3.0.5
Fix Version/s: None

Type: Improvement Priority: Minor - P4
Reporter: Avi Levy Assignee: Amirsaman Memaripour
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Sprint: Service Arch 2022-10-31
Participants:

 Description   

When mongod fails to start because dbpath is not found, the /tmp/mongodb-xxxxx.sock file is not removed.

Original description

Starting mongodb as service fails after trying run mongod (not as service) and failing because /data/db not found.

2015-08-03T11:28:35.657+0000 I CONTROL ***** SERVER RESTARTED *****
2015-08-03T11:28:35.695+0000 E NETWORK [initandlisten] Failed to unlink socket file /tmp/mongodb-27017.sock errno:1 Operation not permitted
2015-08-03T11:28:35.695+0000 I - [initandlisten] Fatal Assertion 28578
2015-08-03T11:28:35.695+0000 I - [initandlisten]

Deleting the socket file and running as service fixes the problem.



 Comments   
Comment by Amirsaman Memaripour [ 27/Oct/22 ]

Closing as "Gone Away" since this is no longer an issue (at least since v4.2). We start the TransportLayer way after verifying the the dbpath exists. For example, here is where we verify the dbpath on v4.2, and here is where we start the TransportLayer (e.g., create the socket file).

Comment by Lauren Lewis (Inactive) [ 21/Dec/21 ]

We haven’t heard back from you in at least 1 year, so I'm going to close this ticket. If this is still an issue for you, please provide additional information and we will reopen the ticket.

Comment by Avi Levy [ 03/Aug/15 ]

Thanks for explanation Ramon.

I ran plain mongod by mistake (instead or running "service mongod start").
When i fixed my mistake by running it as a service, I was surprised to find it couldn't start.
the log was pretty straight forward about what the problem is, and how to solve it. That is why I opened this issue with the lowest priority.

Thanks,
Avi

Comment by Ramon Fernandez Marina [ 03/Aug/15 ]

Thanks for the additional info levyavi. Here's what happens; when you do the following:

2. Run mongod not as service - fails /data/db not exist

mongod will create /tmp/mongodb-27017.sock, owned by root (because you're running mongod as root). Since you didn't specify a dbpath, mongod tries to use the default path, /data/db, but fails because it doesn't exist.

Later you try to:

3. Run mongo as service - fails

The service is probably configured to run as the mongod user, which has no permissions to remove /tmp/mongodb-27017.sock.

This is expected behavior. Arguably mongod should clean /tmp/mongodb-27017.sock after existing, so we can reuse this ticket to consider this cleanup. That being said, please note it's strongly recommended to not run mongod as root.

Comment by Avi Levy [ 03/Aug/15 ]

@Ramon Fernandez,
I am running all commands as root.
I can repro it. It repros also on another machine.

1. Run mongo - fails becuase mongodb is not running
2. Run mongod not as service - fails /data/db not exist
3. Run mongo as service - fails
4. Check mongo log - failure is because of socket file
5. Check that socket files exist
6. Delete socket file
7. Run mongod as service

[root@foobar init.d]# mongo
MongoDB shell version: 3.0.5
connecting to: test
2015-08-03T17:14:55.416+0000 W NETWORK Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2015-08-03T17:14:55.417+0000 E QUERY Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed
at connect (src/mongo/shell/mongo.js:179:14)
at (connect):1:6 at src/mongo/shell/mongo.js:179
exception: connect failed
[root@foobar init.d]# mongod
2015-08-03T17:15:04.749+0000 I STORAGE [initandlisten] exception in initAndListen: 29 Data directory /data/db not found., terminating
2015-08-03T17:15:04.749+0000 I CONTROL [initandlisten] dbexit: rc: 100
[root@foobar init.d]# service mongod start
Starting mongod: [FAILED]
[root@foobar init.d]# cat /var/log/mongodb/mongod.log
2015-08-03T17:16:50.025+0000 I CONTROL ***** SERVER RESTARTED *****
2015-08-03T17:16:50.115+0000 E NETWORK [initandlisten] Failed to unlink socket file /tmp/mongodb-27017.sock errno:1 Operation not permitted
2015-08-03T17:16:50.115+0000 I - [initandlisten] Fatal Assertion 28578
2015-08-03T17:16:50.115+0000 I - [initandlisten]

***aborting after fassert() failure

[root@foobar init.d]# ll /tmp/mongodb-27017.sock
srwx------ 1 root root 0 Aug 3 17:22 /tmp/mongodb-27017.sock
[root@foobar init.d]# rm /tmp/mongodb-27017.sock
rm: remove socket `/tmp/mongodb-27017.sock'? y
[root@foobar init.d]# service mongod start
Starting mongod:
[ OK ]
[root@foobar init.d]#

Comment by Ramon Fernandez Marina [ 03/Aug/15 ]

levyavi, are you able to reproduce this problem? It is not uncommon for the mongod service to run under a dedicated user, and for users to run it as "root" leaving a socket in the dbpath that can't be unlinked by the service user. Can you please retrace your steps and provide details of what you did, the exact error messages you get and the permissions of the socket file?

Thanks,
Ramón.

Generated at Thu Feb 08 03:51:51 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.