[SERVER-7240] pidfile appears to be overwritten even when lock can not be obtained Created: 02/Oct/12  Updated: 21/Jun/22  Resolved: 10/Jun/22

Status: Closed
Project: Core Server
Component/s: Admin
Affects Version/s: 2.2.0, 2.4.3, 2.6.4
Fix Version/s: 6.1.0-rc0

Type: Bug Priority: Minor - P4
Reporter: Benno Leslie Assignee: Gregory Noma
Resolution: Done Votes: 2
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
is duplicated by SERVER-14338 mongod/s should refuse to overwrite p... Closed
Related
is related to SERVER-67401 Remove unused parameter in initialize... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Sprint: Execution Team 2022-06-13
Participants:
Case:

 Description   

The pidfile appears to be written even in the case where the database can't be started due to lockfile being locked.

E.g:
$ mongod --quiet --dbpath=./backend/scripts/../dev/db --logappend --logpath=db.log --pidfilepath=db.pid --fork
forked process: 94444
$ cat db.pid
94444
$ mongod --quiet --dbpath=./backend/scripts/../dev/db --logappend --logpath=db.log --pidfilepath=db.pid --fork
forked process: 94445
$ cat db.pid
94445
$ ps aux | grep mongo
benno 94444 0.3 0.1 2709580 12572 ?? S 6:09pm 0:00.71 mongod....

I think it would be better if in the case where the lockfile can't be obtained the PID file isn't updated. (i.e: the PID file should be protected by the lockfile).



 Comments   
Comment by Githook User [ 10/Jun/22 ]

Author:

{'name': 'Gregory Noma', 'email': 'gregory.noma@gmail.com', 'username': 'gregorynoma'}

Message: SERVER-7240 Delay writing PID file to the end of startup
Branch: master
https://github.com/mongodb/mongo/commit/3337f39b423aa94d0f3617b66232a0526a19ec83

Comment by Githook User [ 10/Jun/22 ]

Author:

{'name': 'Gregory Noma', 'email': 'gregory.noma@gmail.com', 'username': 'gregorynoma'}

Message: SERVER-7240 Delay writing PID file to the end of startup
Branch: master
https://github.com/10gen/mongo-enterprise-modules/commit/99d5816ab53968c0e8cd7795d1680e4273e3c22a

Comment by Christopher Henderson [ 20/Jul/16 ]

Confirmed for 2.6.8 and 3.2.8.

Comment by Thomas Rueckstiess [ 09/Sep/14 ]

And confirmed for 2.6.4.

Comment by Gianfranco Palumbo [ 22/May/13 ]

This occurs as well on Ubuntu Linux on mongod 2.4.3

$ ./mongod --pidfilepath db.pid --dbpath ~/data
Wed May 22 15:03:13.399 [initandlisten] MongoDB starting : pid=8983 port=27017 dbpath=/home/vagrant/data 64-bit host=lucid64
Wed May 22 15:03:13.400 [initandlisten] db version v2.4.3
Wed May 22 15:03:13.400 [initandlisten] git version: fe1743177a5ea03e91e0052fb5e2cb2945f6d95f
Wed May 22 15:03:13.400 [initandlisten] build info: Linux ip-10-2-29-40 2.6.21.7-2.ec2.v1.2.fc8xen #1 SMP Fri Nov 20 17:48:28 EST 2009 x86_64 BOOST_LIB_VERSION=1_49
Wed May 22 15:03:13.400 [initandlisten] allocator: tcmalloc
Wed May 22 15:03:13.400 [initandlisten] options: { dbpath: "/home/vagrant/data", pidfilepath: "db.pid" }
Wed May 22 15:03:13.407 [initandlisten] journal dir=/home/vagrant/data/journal
Wed May 22 15:03:13.407 [initandlisten] recover : no journal files present, no recovery needed
Wed May 22 15:03:13.411 [websvr] admin web console waiting for connections on port 28017
Wed May 22 15:03:13.411 [initandlisten] waiting for connections on port 27017
...
 
// another session, same directory
$ cat db.pid
8983
 
$ ./mongod --pidfilepath db.pid --dbpath ~/data
Wed May 22 15:03:18.988 [initandlisten] MongoDB starting : pid=8999 port=27017 dbpath=/home/vagrant/data 64-bit host=lucid64
Wed May 22 15:03:18.989 [initandlisten] db version v2.4.3
Wed May 22 15:03:18.989 [initandlisten] git version: fe1743177a5ea03e91e0052fb5e2cb2945f6d95f
Wed May 22 15:03:18.989 [initandlisten] build info: Linux ip-10-2-29-40 2.6.21.7-2.ec2.v1.2.fc8xen #1 SMP Fri Nov 20 17:48:28 EST 2009 x86_64 BOOST_LIB_VERSION=1_49
Wed May 22 15:03:18.989 [initandlisten] allocator: tcmalloc
Wed May 22 15:03:18.989 [initandlisten] options: { dbpath: "/home/vagrant/data", pidfilepath: "db.pid" }
Wed May 22 15:03:18.989 [initandlisten] exception in initAndListen: 10310 Unable to lock file: /home/vagrant/data/mongod.lock. Is a mongod instance already running?, terminating
Wed May 22 15:03:18.989 dbexit:
...
Wed May 22 15:03:18.989 dbexit: really exiting now
 
$ cat db.pid
8999

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