-
Type:
Bug
-
Resolution: Done
-
Priority:
Major - P3
-
Affects Version/s: None
-
Component/s: Internal Code
-
None
-
Fully Compatible
-
ALL
-
-
None
-
None
-
None
-
None
-
None
-
None
-
None
The expectation is that the server should start successfully from any working directory that the OS considers valid. This is especially true when only absolute paths have been specified for dbpath and logpath, and if --fork is used (whereupon the server will chdir to /).
See also SERVER-24916.
Success case:
kev@genique:~$ cd /tmp
kev@genique:/tmp$ mongod --dbpath /tmp/data
2016-07-06T11:51:57.347+1000 I CONTROL [initandlisten] MongoDB starting : pid=24560 port=27017 dbpath=/tmp/data 64-bit host=genique
2016-07-06T11:51:57.347+1000 I CONTROL [initandlisten] db version v3.2.6
2016-07-06T11:51:57.347+1000 I CONTROL [initandlisten] git version: 05552b562c7a0b3143a729aaa0838e558dc49b25
2016-07-06T11:51:57.347+1000 I CONTROL [initandlisten] allocator: tcmalloc
2016-07-06T11:51:57.347+1000 I CONTROL [initandlisten] modules: none
2016-07-06T11:51:57.347+1000 I CONTROL [initandlisten] build environment:
2016-07-06T11:51:57.347+1000 I CONTROL [initandlisten] distarch: x86_64
2016-07-06T11:51:57.347+1000 I CONTROL [initandlisten] target_arch: x86_64
2016-07-06T11:51:57.347+1000 I CONTROL [initandlisten] options: { storage: { dbPath: "/tmp/data" } }
2016-07-06T11:51:57.368+1000 E NETWORK [initandlisten] listen(): bind() failed errno:98 Address already in use for socket: 0.0.0.0:27017
2016-07-06T11:51:57.368+1000 E NETWORK [initandlisten] addr already in use
2016-07-06T11:51:57.368+1000 E STORAGE [initandlisten] Failed to set up sockets during startup.
2016-07-06T11:51:57.368+1000 I CONTROL [initandlisten] dbexit: rc: 48
kev@genique:/tmp$
Failure case:
kev@genique:/tmp$ cd $d
kev@genique:/tmp/0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789/0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789/0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789/0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789/0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789/0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789/0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789/0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789/0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789/0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789$ mongod --dbpath /tmp/data
2016-07-06T11:52:10.470+1000 I - [main] Assertion failure getcwd(buffer, 1000) src/mongo/db/server_options_helpers.cpp 450
2016-07-06T11:52:10.476+1000 I CONTROL [main]
0x12fa192 0x12a5538 0x1291074 0xf87cc1 0xcd0476 0x962ccb 0x95fa24 0x96ac2b 0x96b2dc 0x96b60e 0x962678 0x7f2d89ef2ec5 0x959d09
----- BEGIN BACKTRACE -----
{"backtrace":[{"b":"400000","o":"EFA192","s":"_ZN5mongo15printStackTraceERSo"},{"b":"400000","o":"EA5538","s":"_ZN5mongo10logContextEPKc"},{"b":"400000","o":"E91074","s":"_ZN5mongo12verifyFailedEPKcS1_j"},{"b":"400000","o":"B87CC1","s":"_ZN5mongo18storeServerOptionsERKNS_17optionenvironment11EnvironmentERKSt6vectorISsSaISsEE"},{"b":"400000","o":"8D0476","s":"_ZN5mongo18storeMongodOptionsERKNS_17optionenvironment11EnvironmentERKSt6vectorISsSaISsEE"},{"b":"400000","o":"562CCB","s":"_ZN5mongo45_mongoInitializerFunction_MongodOptions_StoreEPNS_18InitializerContextE"},{"b":"400000","o":"55FA24","s":"_ZNSt17_Function_handlerIFN5mongo6StatusEPNS0_18InitializerContextEEPS4_E9_M_invokeERKSt9_Any_dataS3_"},{"b":"400000","o":"56AC2B","s":"_ZNK5mongo11Initializer7executeERKSt6vectorISsSaISsEERKSt3mapISsSsSt4lessISsESaISt4pairIKSsSsEEE"},{"b":"400000","o":"56B2DC","s":"_ZN5mongo21runGlobalInitializersERKSt6vectorISsSaISsEERKSt3mapISsSsSt4lessISsESaISt4pairIKSsSsEEE"},{"b":"400000","o":"56B60E","s":"_ZN5mongo21runGlobalInitializersEiPKPKcS3_"},{"b":"400000","o":"562678","s":"main"},{"b":"7F2D89ED1000","o":"21EC5","s":"__libc_start_main"},{"b":"400000","o":"559D09"}]}
mongod(_ZN5mongo15printStackTraceERSo+0x32) [0x12fa192]
mongod(_ZN5mongo10logContextEPKc+0x138) [0x12a5538]
mongod(_ZN5mongo12verifyFailedEPKcS1_j+0xB4) [0x1291074]
mongod(_ZN5mongo18storeServerOptionsERKNS_17optionenvironment11EnvironmentERKSt6vectorISsSaISsEE+0x2C01) [0xf87cc1]
mongod(_ZN5mongo18storeMongodOptionsERKNS_17optionenvironment11EnvironmentERKSt6vectorISsSaISsEE+0x26) [0xcd0476]
mongod(_ZN5mongo45_mongoInitializerFunction_MongodOptions_StoreEPNS_18InitializerContextE+0x2B) [0x962ccb]
mongod(_ZNSt17_Function_handlerIFN5mongo6StatusEPNS0_18InitializerContextEEPS4_E9_M_invokeERKSt9_Any_dataS3_+0x14) [0x95fa24]
mongod(_ZNK5mongo11Initializer7executeERKSt6vectorISsSaISsEERKSt3mapISsSsSt4lessISsESaISt4pairIKSsSsEEE+0x1CB) [0x96ac2b]
mongod(_ZN5mongo21runGlobalInitializersERKSt6vectorISsSaISsEERKSt3mapISsSsSt4lessISsESaISt4pairIKSsSsEEE+0x2C) [0x96b2dc]
mongod(_ZN5mongo21runGlobalInitializersEiPKPKcS3_+0x31E) [0x96b60e]
mongod(main+0x68) [0x962678]
libc.so.6(__libc_start_main+0xF5) [0x7f2d89ef2ec5]
mongod(+0x559D09) [0x959d09]
----- END BACKTRACE -----
2016-07-06T11:52:10.476+1000 F CONTROL [main] Failed global initialization: UnknownError: assertion src/mongo/db/server_options_helpers.cpp:450
kev@genique:/tmp/0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789/0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789/0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789/0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789/0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789/0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789/0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789/0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789/0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789/0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789$
https://github.com/mongodb/mongo/blob/r3.3.9/src/mongo/db/server_options_helpers.cpp#L458-L468
Status setupCwd() {
// setup cwd
char buffer[1024];
#ifdef _WIN32
verify(_getcwd(buffer, 1000));
#else
verify(getcwd(buffer, 1000));
#endif
serverGlobalParams.cwd = buffer;
return Status::OK();
}
A quick and easy (though partial) fix is to just change the hardcoded 1024 and 1000 to PATH_MAX (which POSIX defines as >= 4096), so as to be better aligned with OS limits (though not definitively so).
It turns out that POSIX requires PATH_MAX >= 256 (or >= 1024 for XSI). Darwin/OSX and Solaris are 1024, but Linux is 10k or more.
A fuller (but more involved) fix would be to dynamically allocate and grow the buffer as necessary.
- is related to
-
SERVER-24915 getcwd() failure should report errno
-
- Closed
-
-
SERVER-24916 Only get current working directory (cwd) when necessary
-
- Closed
-
-
SERVER-25556 Improve behaviour of ProgramRunner::findProgram
-
- Closed
-