[SERVER-388] invalid ensureIndex crashes mongod server Created: 26/Oct/09  Updated: 12/Jul/16  Resolved: 26/Oct/09

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

Type: Bug Priority: Major - P3
Reporter: Doug Green Assignee: Eliot Horowitz (Inactive)
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

linux-x86_64-1.0.1, but it's one we compiled ourself with boost 1_38 libs, and not the distro


Participants:

 Description   

The mongod server crashes when the c++ client sends a bad ensureIndex(). Here's the code (http://pastebin.com/d744f024)

void statstore_mongo::init(vector<string>& options) {
dbconn_.reset(new DBClientConnection());
try

{ string host = options.size() > 1 ? options[1] : "localhost"; dbconn_->connect(host); BSONObjBuilder b; b.append("stat_id", 1); b.append("word", 1); BSONObj obj = b.obj(); dbconn_->ensureIndex("retweet", obj); // This crashes the server on the second ensureIndex(). dbconn_->ensureIndex("hashtags", obj); dbconn_->ensureIndex("location", obj); dbconn_->ensureIndex("keywords", obj); }

catch (const UserException& e)

{ string what("Unable to open mongo database connection: "); what.append(e.what()); throw runtime_error(what); }

}

And here's a partial log:

Mon Oct 26 21:27:54 git version: 73ed0277ffabb283f315b1da18a90c9c889b4924
Mon Oct 26 21:27:54 sys info: Linux dev3.node01.nowpublic.com 2.6.18-92.1.18.el5.028stab060.2 #1 SMP Tue Jan 13 11:38:36 MSK 2009 x86_64
Mon Oct 26 21:27:54 waiting for connections on port 27017
Mon Oct 26 21:28:24 connection accepted from 67.220.204.51:42115 #1
Mon Oct 26 21:28:24 building new index on

{ stat_id: 1, word: 1 }

for retweet...
Mon Oct 26 21:28:24 Buildindex retweet idxNo:1 { ns: "retweet", key:

{ stat_id: 1, word: 1 }

, name: "stat_id_1_word_1" }
Mon Oct 26 21:28:24 done for 9 records 0secs
Mon Oct 26 21:28:24 end connection 67.220.204.51:42115
Mon Oct 26 21:30:57 connection accepted from 67.220.204.51:21982 #2
Mon Oct 26 21:30:57 allocating new datafile /usr/local/mongodb/bin/../data/hashtags.ns, filling with zeroes...
Mon Oct 26 21:30:57 done allocating datafile /usr/local/mongodb/bin/../data/hashtags.ns, size: 16MB, took 0.048 secs
Mon Oct 26 21:30:57 allocating new datafile /usr/local/mongodb/bin/../data/hashtags.0, filling with zeroes...
Mon Oct 26 21:30:57 done allocating datafile /usr/local/mongodb/bin/../data/hashtags.0, size: 64MB, took 0.197 secs
Mon Oct 26 21:30:57 Got signal: 11 (Segmentation fault).
Mon Oct 26 21:30:57 Backtrace:
0x58f539 0x2b6785d0f1b0 0x5540d6 0x54f438 0x550ec3 0x539cb0 0x53e226 0x590c36 0x5a7727 0x2b67853292f7 0x2b6785db0e3d
./mongod(_ZN5mongo10abruptQuitEi+0x399) [0x58f539]
/lib64/libc.so.6 [0x2b6785d0f1b0]
./mongod [0x5540d6]
./mongod [0x54f438]
./mongod [0x550ec3]
./mongod [0x539cb0]
./mongod [0x53e226]
./mongod(_ZN5mongo10connThreadEv+0x1f6) [0x590c36]
./mongod [0x5a7727]
/lib64/libpthread.so.0 [0x2b67853292f7]
/lib64/libc.so.6(clone+0x6d) [0x2b6785db0e3d]
Mon Oct 26 21:30:57 dbexit:
Mon Oct 26 21:30:57 shutdown: going to flush oplog...
Mon Oct 26 21:30:57 shutdown: going to close sockets...
Mon Oct 26 21:30:57 shutdown: waiting for fs...
Mon Oct 26 21:30:57 shutdown: closing all files...
Mon Oct 26 21:30:57 closeAllFiles() finished
Mon Oct 26 21:30:57 shutdown: removing fs lock...
Mon Oct 26 21:30:57 dbexit: really exiting now
ERROR: Client::shutdown not called!



 Comments   
Comment by auto [ 07/Dec/09 ]

Author:

{'name': 'Eliot Horowitz', 'email': 'eliot@10gen.com'}

Message: fix invalid ensureIndex crashing server SERVER-388

Conflicts:

db/pdfile.cpp
jstests/indexapi.js
http://github.com/mongodb/mongo/commit/57a6542753bed4a78d6bece5cb44143732b3e45e

Comment by Doug Green [ 27/Oct/09 ]

Ahh, this crash was caused by my misunderstanding of databases and collection. If I pass "dbname.collectionname" instead of just "collectionname" it doesn't seem to crash. You probably need a check for people like me just passing a single name instead of the fully qualified collectionname.

Comment by Doug Green [ 27/Oct/09 ]

On further review, I don't think it has anything to do with the multiple indexes, but it appears to be a problem creating any index using this code, the first time.

Comment by Eliot Horowitz (Inactive) [ 26/Oct/09 ]

fixed the crash.
the issue is that the call should be:
dbconn_->ensureIndex("mydb.hashtags", obj);

so it actually was the first call crashing the server, not the 2nd.

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