[SERVER-35785] mongod crash on startup when passing -f on directory instead of file Created: 25/Jun/18 Updated: 29/Oct/23 Resolved: 21/Sep/18 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Admin |
| Affects Version/s: | None |
| Fix Version/s: | 4.1.4 |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Norberto Fernando Rocha Leite (Inactive) | Assignee: | Annie Black |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | neweng | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Backwards Compatibility: | Fully Compatible |
| Operating System: | ALL |
| Sprint: | Platforms 2018-07-30, Platforms 2018-08-13, Platforms 2018-08-27, Platforms 2018-09-10, Platforms 2018-09-24 |
| Participants: |
| Description |
|
I accidentally was trying to launch a mongod (4.0.0-rc7) passing a directory instead of file and got this stack trace in return.
This was caused by pilot error, nevertheless `mongod` probably should not error out this way. |
| Comments |
| Comment by Githook User [ 21/Sep/18 ] | |||
|
Author: {'name': 'ablack12', 'email': 'annie.black@10gen.com', 'username': 'ablack12'}Message: | |||
| Comment by ADAM Martin (Inactive) [ 25/Jul/18 ] | |||
|
Addendum: BSD based systems (including OSX) have slightly different semantics from SYSV based systems (or those inspired by SYSV, like Linux), when it comes to file-style IO on a directory. IIRC, BSD based systems are incredibly forgiving, and permit direct reading of the raw directory file's dirent encodings. POSIX forbids `fopen` in write mode on a directory, issuing an errno: EISDIR. However it is silent on read-only access. Further, `open` in POSIX, which underlies `fopen`, is not forbidden on directories, when opening read-only | |||
| Comment by ADAM Martin (Inactive) [ 25/Jul/18 ] | |||
|
The error text `"Error reading in config file:"` comes from later in the configuration parsing logic, after the memory allocation: https://github.com/mongodb/mongo/blob/ab0c426e60c4bdcc49b5a48a93f84828414d5ba6/src/mongo/util/options_parser/options_parser.cpp#L897 However, the nearly identical error text: `"Error reading config file:"` comes earlier in this logic: https://github.com/mongodb/mongo/blob/ab0c426e60c4bdcc49b5a48a93f84828414d5ba6/src/mongo/util/options_parser/options_parser.cpp#L859 Therefore, it appears that regardless of platform, a large amount of memory is requested. Probably depending upon system over-provisioning options and other variables, the allocation may succeed or fail. If the allocation succeeds (allocating -1 bytes, which becomes "absurdly large"), then the results of `ftell` are used and the -1 is detected because an absurdly large amount of data to read is sent to `fread`, thus causing it to fail here: https://github.com/mongodb/mongo/blob/ab0c426e60c4bdcc49b5a48a93f84828414d5ba6/src/mongo/util/options_parser/options_parser.cpp#L892 The check for a negative return from `ftell` should probably be moved earlier. Also, considering the age of this file and a few other potential problems I see in the configuration file logic we may want to consider investing some time into improving this code. | |||
| Comment by Mark Benvenuto [ 25/Jun/18 ] | |||
|
This does not repro for me on Fedora 28. It does repro on Ubuntu 16.04. In this case, ftell() is returning a -1 indicating an error. This -1 is then used to allocate memory. On Fedora 28 (Glibc 2.27), ftell returns 178. | |||
| Comment by Ramon Fernandez Marina [ 25/Jun/18 ] | |||
|
I can reproduce this on Ubuntu 16.04 with 3.4.15 and 3.6.5, while in macOS I get:
|