[SERVER-22364] Fix confusing error message when pid file can't be written to Created: 29/Jan/16  Updated: 16/Mar/16  Resolved: 25/Feb/16

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

Type: Bug Priority: Minor - P4
Reporter: Ramon Fernandez Marina Assignee: Matt Cotter
Resolution: Done Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to SERVER-22072 Unable to start service with error " ... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Sprint: Platforms 10 (02/19/16), Platforms 11 (03/11/16)
Participants:

 Description   

When the mongod process can't write to the pid file the following message may appear:

ERROR: Cannot write pid file to /var/run/mongodb/mongod.pid: Success

In mongo/util/processinfo.cpp we have:

class PidFileWiper {
public:
    ~PidFileWiper() {
        if (path.empty()) {
            return;
        }
 
        ofstream out(path.c_str(), ios_base::out);
        out.close();
    }
 
    bool write(const string& p) {
        path = p;
        ofstream out(path.c_str(), ios_base::out);
        out << ProcessId::getCurrent() << endl;
        return out.good();
    }
 
    string path;
} pidFileWiper;
 
bool writePidFile(const string& path) {
    bool e = pidFileWiper.write(path);
    if (!e) {
        log() << "ERROR: Cannot write pid file to " << path << ": " << strerror(errno);
    }
    return e;
}

The errno value is not reliable with C++ iostreams.

Observed in MongoDB 3.0.5; see SERVER-22072 for more details.



 Comments   
Comment by Githook User [ 25/Feb/16 ]

Author:

{u'username': u'Machyne', u'name': u'Matt Cotter', u'email': u'matt.cotter@mongodb.com'}

Message: SERVER-22364 threadsafe errno printing, pidfile error fix

If the errno is set after a pidfile write failure, then it will get
printed, otherwise this will print "Unable to determine OS error".
Branch: master
https://github.com/mongodb/mongo/commit/6f21482980d5a9be067d047f4601ad9ef8256d01

Generated at Thu Feb 08 04:00:11 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.