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

Fix late calls to errnoWithDescription()

    • Fully Compatible
    • v5.0, v4.4
    • Service Arch 2022-03-21, Service Arch 2022-04-04, Service Arch 2022-04-18, Service Arch 2022-05-02, Service Arch 2022-05-16
    • 4

      Calling errnoWithDescription() without any arguments causes it to refer to the errno global. However, unless this is done immediately after returning from a function call that might set errno, the value of errno might get trampled by other code which calls errno-setting functions. This can cause the wrong error string to be reported by the failure message, including situations where an error is reported, but the cause of the error is confusingly "Success".

      There are currently 100 call sites of errnoWithDescription() with no args (and 1 in enterprise). 62 of these are inside the streaming operator, which is too late (at least potentially, because the constructor of the object being streamed into might do something that resets errno).

      This ticket is to audit all usages of errnoWithDescription() with no args, and clean up those where it's called too late — or come up with some sane way to automatically capture the relevant value of errno before there is any possibility of it being overwritten.

      $ git describe
      r4.1.12-20-g20309e67435
      $ rg 'errnoWithDescription\(\)'
      transport/transport_layer_asio.cpp
      817:                const auto ewd = errnoWithDescription();
      
      logger/rotatable_file_writer.cpp
      237:                // TODO(schwerin): Make errnoWithDescription() available in the logger library, and
      
      db/server_options_test.cpp
      902:    ASSERT_NOT_EQUALS(pid, -1) << "unable to fork: " << ::mongo::errnoWithDescription();
      
      dbtests/jsontests.cpp
      422:            FAIL(errnoWithDescription());
      438:                FAIL(errnoWithDescription());
      451:                FAIL(errnoWithDescription());
      
      shell/shell_utils_extended.cpp
      144:    uasserted(16832, str::stream() << "cd command failed: " << errnoWithDescription());
      
      shell/shell_utils_launcher.cpp
      134:        const auto ewd = errnoWithDescription();
      411:            const auto ewd = errnoWithDescription();
      422:            const auto ewd = errnoWithDescription();
      428:            const auto ewd = errnoWithDescription();
      632:        const auto ewd = errnoWithDescription();
      663:        const auto ewd = errnoWithDescription();
      711:        const auto ewd = errnoWithDescription();
      730:        const auto ewd = errnoWithDescription();
      920:            const auto ewd = errnoWithDescription();
      964:        const auto ewd = errnoWithDescription();
      973:            const auto ewd = errnoWithDescription();
      
      shell/dbshell.cpp
      720:        std::cout << "couldn't create temp file (" << filename << "): " << errnoWithDescription()
      759:        std::cout << "couldn't open temp file on return from editor: " << errnoWithDescription()
      770:            std::cout << "failed to read temp file: " << errnoWithDescription() << std::endl;
      
      util/errno_util.h
      44: * Return the errno (error number) and the errnoWithDescription() string.
      49: * Return a string with the given prefix followed by the errnoWithDescription() string.
      
      platform/shared_library_windows.cpp
      61:                                                                        << errnoWithDescription());
      79:                                                   << errnoWithDescription());
      
      shell/linenoise.cpp
      2783:        const auto ewd = mongo::errnoWithDescription();
      2788:        const auto ewd = mongo::errnoWithDescription();
      2796:        const auto ewd = mongo::errnoWithDescription();
      2804:                const auto ewd = mongo::errnoWithDescription();
      2814:        const auto ewd = mongo::errnoWithDescription();
      2829:        const auto ewd = mongo::errnoWithDescription();
      2849:        const auto ewd = mongo::errnoWithDescription();
      2856:        const auto ewd = mongo::errnoWithDescription();
      
      db/initialize_server_global_state.cpp
      123:            cout << "ERROR: stage 1 fork() failed: " << errnoWithDescription();
      159:            cout << "ERROR: stage 2 fork() failed: " << errnoWithDescription();
      
      util/file.cpp
      211:          << errnoWithDescription();
      218:              << errnoWithDescription();
      232:    log() << "In File::len(), lseek for '" << _name << "' failed with " << errnoWithDescription();
      253:              << errnoWithDescription();
      262:              << errnoWithDescription();
      284:              << errnoWithDescription() << std::endl;
      295:              << errnoWithDescription();
      
      util/processinfo_linux.cpp
      74:            ss << "couldn't open [" << name << "] " << errnoWithDescription();
      604:        log() << "mincore failed: " << errnoWithDescription();
      615:        log() << "mincore failed: " << errnoWithDescription();
      
      util/processinfo_freebsd.cpp
      175:        log() << "mincore failed: " << errnoWithDescription();
      185:        log() << "mincore failed: " << errnoWithDescription();
      
      util/processinfo_solaris.cpp
      72:                str::stream() << "couldn't open \"/proc/self/psinfo\": " << errnoWithDescription(),
      89:                str::stream() << "couldn't open \"/proc/self/usage\": " << errnoWithDescription(),
      201:        warning() << "lgrp_init failed: " << errnoWithDescription();
      210:        warning() << "lgrp_nlgrps failed: " << errnoWithDescription();
      226:        log() << "mincore failed: " << errnoWithDescription();
      237:        log() << "mincore failed: " << errnoWithDescription();
      
      db/startup_warnings_mongod.cpp
      204:                warning() << "failed to read from /proc/self/numa_maps: " << errnoWithDescription()
      310:        const auto errmsg = errnoWithDescription();
      351:        const auto errmsg = errnoWithDescription();
      
      util/stacktrace_windows.cpp
      88:                    << errnoWithDescription();
      
      util/shell_exec.cpp
      72:                              << errnoWithDescription(),
      78:                              << errnoWithDescription(),
      83:                              << errnoWithDescription(),
      89:                              << errnoWithDescription(),
      94:                str::stream() << "Unable to launch command: " << errnoWithDescription(),
      114:                              << errnoWithDescription(),
      119:                    str::stream() << "Failed terminating subprocess: " << errnoWithDescription(),
      134:                              << errnoWithDescription(),
      147:            return {ErrorCodes::OperationFailed, errnoWithDescription()};
      160:                str::stream() << "Failed reading from subprocess: " << errnoWithDescription(),
      211:                str::stream() << "Unable to launch command: " << errnoWithDescription(),
      237:            return {ErrorCodes::OperationFailed, errnoWithDescription()};
      
      util/processinfo_openbsd.cpp
      194:        log() << "mincore failed: " << errnoWithDescription();
      204:        log() << "mincore failed: " << errnoWithDescription();
      
      util/password.cpp
      62:            std::cerr << "Cannot get terminal attributes " << errnoWithDescription() << std::endl;
      69:            std::cerr << "Cannot set terminal attributes " << errnoWithDescription() << std::endl;
      80:            std::cerr << "Cannot set terminal attributes " << errnoWithDescription() << std::endl;
      
      util/time_support_test.cpp
      62:        return Status(ErrorCodes::BadValue, errnoWithDescription());
      
      util/processinfo_osx.cpp
      226:        log() << "mincore failed: " << errnoWithDescription();
      235:        log() << "mincore failed: " << errnoWithDescription();
      
      db/storage/storage_engine_metadata.cpp
      236:                          << errnoWithDescription(),
      276:                              << errnoWithDescription());
      287:                                        << errnoWithDescription());
      
      util/signal_handlers.cpp
      136:        warning() << "eventProcessingThread CreateEvent failed: " << errnoWithDescription();
      146:                      << errnoWithDescription();
      
      db/storage/remove_saver.cpp
      95:                     << " for remove saving: " << redact(errnoWithDescription());
      119:                     << " for remove saving: " << redact(errnoWithDescription());
      135:                                       << " for remove saving: " << redact(errnoWithDescription());
      170:                                   << " for remove saving: " << redact(errnoWithDescription());
      
      db/storage/storage_repair_observer.cpp
      114:                 << errnoWithDescription();
      
      util/errno_util.cpp
      120:    const auto suffix = errnoWithDescription();
      
      db/storage/storage_file_util.cpp
      76:                              << errnoWithDescription()};
      
      db/storage/storage_engine_lock_file_posix.cpp
      72:                          << errnoWithDescription(),
      
      util/net/sock.cpp
      148:        error() << "disableNagle failed: " << errnoWithDescription();
      152:        error() << "SO_KEEPALIVE failed: " << errnoWithDescription();
      644:                  << " remote host " << remoteString() << ")" << causedBy(errnoWithDescription());
      670:                      << causedBy(errnoWithDescription());
      
      util/net/ssl_manager_openssl.cpp
      1209:                str::stream() << "error opening system CA store: " << errnoWithDescription()};
      1726:                error() << "The SSL BIO reported an I/O error " << errnoWithDescription();
      
      util/net/socket_utils.cpp
      74:            log() << "ERROR: wsastartup failed " << errnoWithDescription();
      151:                error() << "can't get " << optname << ": " << errnoWithDescription();
      157:                    error() << "can't set " << optname << ": " << errnoWithDescription();
      201:        log() << "can't get this server's hostname " << errnoWithDescription();
      

      Acceptance criteria: Remove the errnoWithDescription overload that takes no arguments and fix the affected call sites.

            Assignee:
            billy.donahue@mongodb.com Billy Donahue
            Reporter:
            kevin.pulo@mongodb.com Kevin Pulo
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: