Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-22364

Fix confusing error message when pid file can't be written to

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • 3.3.3
    • Affects Version/s: None
    • Component/s: Admin
    • None
    • Fully Compatible
    • ALL
    • Platforms 10 (02/19/16), Platforms 11 (03/11/16)

      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.

            Assignee:
            matt.cotter Matt Cotter
            Reporter:
            ramon.fernandez@mongodb.com Ramon Fernandez Marina
            Votes:
            1 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: