Re: [PHP Driver] Segmentation Fault

319 views
Skip to first unread message

Adam C

unread,
Aug 30, 2012, 6:36:17 AM8/30/12
to mongod...@googlegroups.com
Hi Bob,

Can you post the seg fault details and the code that leads to it?

Does it segfault if you insert even dummy data first?

Thanks,

Adam

On Thursday, August 30, 2012 10:46:14 AM UTC+1, bobdewhirst wrote:
Hi all,

Just starting out with Mongo :)  I've got a simple script that takes data from MySQL and inserts it as documents into collections within a Mongo database.  I have a weird issue that when I do the transfer to a NEW collection it ALWAYS ends with a Segmentation Fault.  If the collection already exists then it works without error.  As the MySQL data is an unknown quantity I can't pre-create the collections.  I've tried a few previous versions of the PHP driver and I get the same error.  Could anyone help?

PHP Driver version: 1.2.10
Mongo: 2.2.0

Thanks!
Bob.

bobdewhirst

unread,
Aug 30, 2012, 6:56:23 AM8/30/12
to mongod...@googlegroups.com
Hi Adam,

Sure, here it is:

$dbc = mysql db connection
$midnight = strtotime("00:00:00");
$mongo = new Mongo();
$database = $mongo->selectDB('streamStats');

// loads up all the MySQL table names from a given database then calls:

function copyDataFromSQLTableToMongoCollection($tableName, $streamId)
{
global $midnight, $dbc, $database;
$collection = $database->selectCollection("stream$streamId");
$sql = "select timestamp, value from $tableName where timestamp < $midnight";
foreach( $dbc->query($sql) as $row )
{
$document = array(
'timestamp' => $row['timestamp'],
'value' => $row['value']
);
$collection->insert($document);
}
}

The script executes fine and the data is transferred successfully, but the script output always ends with "Segmentation Fault", which I'm worried about for production.  How do I get the details of the segfault for you?

Thanks!
Bob.

bobdewhirst

unread,
Aug 30, 2012, 6:57:53 AM8/30/12
to mongod...@googlegroups.com
Sorry, forgot to answer your second question, if the collection already exists, there is no error, no segfault.

Derick Rethans

unread,
Aug 30, 2012, 6:59:33 AM8/30/12
to mongod...@googlegroups.com
On Thu, 30 Aug 2012, bobdewhirst wrote:

> Just starting out with Mongo :) I've got a simple script that takes
> data from MySQL and inserts it as documents into collections within a
> Mongo database. I have a weird issue that when I do the transfer to a
> NEW collection it ALWAYS ends with a Segmentation Fault. If the
> collection already exists then it works without error. As the MySQL
> data is an unknown quantity I can't pre-create the collections. I've
> tried a few previous versions of the PHP driver and I get the same
> error. Could anyone help?

Could you please:
- upgrade to the latest version: 1.2.12
- and if it still segfaults, provide a reproducable script?

cheers,
Derick

--
{
website: [ "http://mongodb.org", "http://derickrethans.nl" ],
twitter: [ "@derickr", "@mongodb" ]
}

bobdewhirst

unread,
Aug 30, 2012, 7:21:11 AM8/30/12
to mongod...@googlegroups.com
Hello Derick,

Updated to 1.2.12 and still get the fault.  Here's a test script:

$mongo = new Mongo();
$database = $mongo->selectDB('testDatabase');
$collection = $database->selectCollection("testCollection");

$numberOfInserts = 10000;

for( $i=0; $i<$numberOfInserts; $i++ )
{
$document = array(
'timestamp' => time(),
'value' => $i
);
$collection->save($document);
}

The script runs and the data is present in Mongo, but at the end: Segmentation fault

Cheers,
Bob.

bobdewhirst

unread,
Aug 30, 2012, 7:27:24 AM8/30/12
to mongod...@googlegroups.com
If I run the same script again, now that the database and collection exist, there are no errors, no segfault.

bobdewhirst

unread,
Aug 30, 2012, 10:13:53 AM8/30/12
to mongod...@googlegroups.com
Right, well I just tried it on a different server and it works.  I wonder if it's the PHP version?  The original is 5.2 and the one I just used is 5.3.  Might it be that?

Jeremy Mikola

unread,
Aug 31, 2012, 12:28:21 AM8/31/12
to mongod...@googlegroups.com
On Thursday, August 30, 2012 10:13:53 AM UTC-4, bobdewhirst wrote:
Right, well I just tried it on a different server and it works.  I wonder if it's the PHP version?  The original is 5.2 and the one I just used is 5.3.  Might it be that?

I just ran the script on two machines, one with PHP 5.3.10 and another with PHP 5.4.6, without error. I could only suggest trying it on another machine with 5.2 to narrow it down. Your best option is to generate a backtrace to properly debug the source of the error.

Given how MongoCollection objects are created in the driver (either via their constructor or MongoDB::selectCollection(), which chains to that constructor), I don't see how the collection existing or not in the database would affect anything. It's also curious that the segfault would happen after the Mongo operations complete.
 

bobdewhirst

unread,
Aug 31, 2012, 5:22:43 AM8/31/12
to mongod...@googlegroups.com
Hi Jeremy,

Thanks for the reply and for your testing!  I've shifted mongo to the second machine with PHP 5.3 and it seems to be working fine.  I've read about generating backtraces, the machine that is failing is running some production services, so I can't mess around with it too much; though I'd love to know what was causing the error!

Cheers,
Bob.

bobdewhirst

unread,
Sep 3, 2012, 6:08:50 AM9/3/12
to mongod...@googlegroups.com
Started getting segfaults on the other machine now!  I've traced it back to whatever the difference is between selectCollection() and createCollection().  If I use selectCollection() where the collection doesn't currently exist, it segfaults at the end.  If I use createCollection() on a collection that exists or not, it works.

Hopefully this points someone else in the right direction, or might help someone work out what's up with selectCollection!

Cheers,
Bob.
Reply all
Reply to author
Forward
0 new messages