[SERVER-41047] errnoWithDescription always returns "Unknown error" on Linux Created: 08/May/19  Updated: 29/Oct/23  Resolved: 29/May/19

Status: Closed
Project: Core Server
Component/s: Internal Code
Affects Version/s: 4.0.0
Fix Version/s: 4.1.13, 4.0.11

Type: Bug Priority: Major - P3
Reporter: Kevin Pulo Assignee: Kevin Pulo
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Linux


Issue Links:
Backports
Duplicate
is duplicated by SERVER-40693 Mongo shell should surface errors fro... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Backport Requested:
v4.0
Sprint: Sharding 2019-05-20, Sharding 2019-06-03
Participants:

 Description   

Discovered on SERVER-40953, introduced on SERVER-34006, partial (incomplete) fixes on SERVER-39604, SERVER-38935, SERVER-37435, reduced diagnostics on SERVER-40693, SERVER-36809, SERVER-36600, SERVER-38633, SERVER-31081 and probably others.

The cause is that #if !(__ANDROID_API__ <= 22) evaluates to false when __ANDROID_API__ isn't defined. This causes errnoWithDescription() to erroneously call the GNU strerror_r() from the code which handles the XSI strerror_r() variant. Since the GNU function always returns a non-NULL char * pointer, but XSI uses 0 for success and non-zero for failure, errnoWithDescription() always ends up returning kUnknownMsg.

Linux:

$ HOME=/root /omni/4.0.0/bin/mongo --nodb
MongoDB shell version v4.0.0
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
        http://docs.mongodb.org/
Questions? Try the support group
        http://groups.google.com/group/mongodb-user
2019-05-06T16:31:28.707+1000 I STORAGE  [main] In File::open(), ::open for '/root/.mongorc.js' failed with Unknown error
2019-05-06T16:31:28.707+1000 E -        [main] Error loading history file: FileOpenFailed: Unable to fopen() file /root/.dbshell: Unknown error
>
bye
2019-05-06T16:31:29.845+1000 E -        [main] Error saving history file: FileOpenFailed: Unable to open() file /root/.dbshell: Unknown error
$ HOME=/root /omni/3.6.12/bin/mongo --nodb
MongoDB shell version v3.6.12
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
        http://docs.mongodb.org/
Questions? Try the support group
        http://groups.google.com/group/mongodb-user
2019-05-06T17:32:44.895+1000 I STORAGE  [main] In File::open(), ::open for '/root/.mongorc.js' failed with Permission denied
2019-05-06T17:32:44.896+1000 E -        [main] Error loading history file: FileOpenFailed: Unable to fopen() file /root/.dbshell: Permission denied
>
bye
2019-05-06T17:32:46.054+1000 E -        [main] Error saving history file: FileOpenFailed: Unable to open() file /root/.dbshell: Permission denied
$ 

MacOS:

$ HOME=/ mongo --nodb
MongoDB shell version v4.0.6
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
    http://docs.mongodb.org/
Questions? Try the support group
    http://groups.google.com/group/mongodb-user
2019-05-06T15:23:51.115+1000 I STORAGE  [main] In File::open(), ::open for '//.mongorc.js' failed with Permission denied
>
bye
2019-05-06T15:24:13.495+1000 E -        [main] Error saving history file: FileOpenFailed: Unable to open() file //.dbshell: Permission denied
$ 

Windows:

C:\>mongo --nodb
MongoDB shell version v4.0.4
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
        http://docs.mongodb.org/
Questions? Try the support group
        http://groups.google.com/group/mongodb-user
2019-05-06T15:35:05.212+1000 I STORAGE  [main] In File::open(), CreateFileW for 'C:\\.mongorc.js' failed with A required privilege is not held by the client.
> exit
bye
2019-05-06T15:40:48.635+1000 E -        [main] Error saving history file: FileOpenFailed: Unable to fopen() file C:\/.dbshell: A required privilege is not held by the client.
 
C:\>

$ cat test-cpp-comparison.cpp
#include <iostream>
 
int main(int argc, char *argv[]) {
#if FOOBARBAZ >= 10
        std::cerr << "unsafe: greater than or equal to 10" << std::endl;
#elif !(FOOBARBAZ >= 10)
        std::cerr << "unsafe: less than 10" << std::endl;
#else
        std::cerr << "unsafe: neither" << std::endl;
#endif
#if defined(FOOBARBAZ) && FOOBARBAZ >= 10
        std::cerr << "safe: greater than or equal to 10" << std::endl;
#elif defined(FOOBARBAZ) && !(FOOBARBAZ >= 10)
        std::cerr << "safe: less than 10" << std::endl;
#else
        std::cerr << "safe: neither" << std::endl;
#endif
        return 0;
}
$ g++ -o test-cpp-comparison test-cpp-comparison.cpp
$ ./test-cpp-comparison
unsafe: less than 10
safe: neither
$



 Comments   
Comment by Githook User [ 29/May/19 ]

Author:

{'name': 'Kevin Pulo', 'email': 'kevin.pulo@mongodb.com', 'username': 'devkev'}

Message: SERVER-41047 errnoWithDescription only check _ANDROID_API_ if it's defined

(cherry picked from commit b6b3e099b3ed0c7e43b133932e021106c59f2249)
Branch: v4.0
https://github.com/mongodb/mongo/commit/2dcb84834472b15bcfe8e94937e634ad56309cb6

Comment by Githook User [ 29/May/19 ]

Author:

{'name': 'Kevin Pulo', 'email': 'kevin.pulo@mongodb.com', 'username': 'devkev'}

Message: SERVER-41047 errnoWithDescription only check _ANDROID_API_ if it's defined
Branch: master
https://github.com/mongodb/mongo/commit/b6b3e099b3ed0c7e43b133932e021106c59f2249

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