[SERVER-2416] inverted conditional maans that FileAllocator::run fails to trap failed open()s Created: 27/Jan/11  Updated: 12/Jul/16  Resolved: 02/Sep/11

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Trivial - P5
Reporter: Nicholas Clark Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Found and fixed on Linux, but I believe the problem to be generic


Attachments: File mongo-16.patch     File mongo-master.patch    
Operating System: ALL
Participants:

 Description   

The code to allocate new data files reads as follows:

try {
log() << "allocating new datafile " << name << ", filling with zeroes..." << endl;
long fd = open(name.c_str(), O_CREAT | O_RDWR | O_NOATIME, S_IRUSR | S_IWUSR);
if ( fd <= 0 )

{ stringstream ss; ss << "couldn't open " << name << ' ' << errnoWithDescription(); massert( 10439 , ss.str(), fd <= 0 ); }

The sense of the conditional on the massert() is inverted. The block is only
entered for an invalid file descriptor, hence within it fd is always <= 0. As
a result, the massert() never actually triggers, and so the error is neither
logged nor trapped at this point.

This isn't actually a big problem, as the invalid value in fd (typically -1)
causes the system calls within ensureLength() to fail pretty soon after.
(The posix_fallocate() fails and warns, and then the fallback code fails the
first lseek(), logs and aborts).

Patches attached for master, and for 1.6.6

Nicholas Clark



 Comments   
Comment by Eliot Horowitz (Inactive) [ 02/Sep/11 ]

was fixed in march, 2011

Generated at Thu Feb 08 02:59:54 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.