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

Incorrect use of WSAGetLastError() to get file system error code (Windows)

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • 2.3.0
    • Affects Version/s: None
    • Component/s: Internal Code
    • Labels:
    • Environment:
      Windows
    • Fully Compatible
    • Windows

      From code inspection:
      src/mongo/db/instance.cpp lines 1008 to 1010:

      #ifdef _WIN32
          if( _chsize( lockFile , 0 ) )
              log() << "couldn't remove fs lock " << WSAGetLastError() << endl;
      

      WSAGetLastError() does not return anything useful here – this is for WinSock errors. Here, it will always print "0".
      Better code would be:

      #ifdef _WIN32
          if( _chsize( lockFile , 0 ) )
              log() << "couldn't remove fs lock " << errnoWithDescription(_doserrno) << endl;
      

      which will print the errno value and the system text, for example:

      couldn't remove fs lock errno:6 The handle is invalid.
      

            Assignee:
            tad Tad Marshall
            Reporter:
            tad Tad Marshall
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: