Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mongodb 4.2.2 server is crashing on model.mapReduce for any query #8438

Closed
inampaki opened this issue Dec 18, 2019 · 7 comments
Closed

mongodb 4.2.2 server is crashing on model.mapReduce for any query #8438

inampaki opened this issue Dec 18, 2019 · 7 comments
Labels
underlying library issue This issue is a bug with an underlying library, like the MongoDB driver or mongodb-core

Comments

@inampaki
Copy link

inampaki commented Dec 18, 2019

My code is working fine for mongodb 4.2.1 server but for version 4.2.2 mongo db server crashes with the following stack trace:

2019-12-19T00:20:41.407+0500 F CONTROL [conn6] *** unhandled exception (access violation) at 0x00007FF6F083898D, terminating
2019-12-19T00:20:41.407+0500 F CONTROL [conn6] *** access violation was a read from 0x0
2019-12-19T00:20:41.407+0500 F CONTROL [conn6] *** stack trace for unhandled exception:
2019-12-19T00:20:41.544+0500 I - [conn6] mongod.exe ...\src\mongo\db\commands\mr.cpp(239) mongo::mr::anonymous namespace'::queryContainsMatchType+0x2d mongod.exe ...\src\mongo\db\commands\mr.cpp(1567) mongo::mr::MapReduceCommand::errmsgRun+0x970 mongod.exe ...\src\mongo\db\commands.cpp(706) mongo::ErrmsgCommandDeprecated::run+0x56 mongod.exe ...\src\mongo\db\commands.cpp(595) mongo::BasicCommand::Invocation::run+0x63 mongod.exe ...\src\mongo\db\service_entry_point_common.cpp(592) mongo::anonymous namespace'::runCommandImpl+0x15c
mongod.exe ...\src\mongo\db\service_entry_point_common.cpp(883) mongo::anonymous namespace'::execCommandDatabase+0x165b mongod.exe ...\src\mongo\db\service_entry_point_common.cpp(1024) <lambda_84801c53d6614de25b816924ff460f13>::operator()+0x431 mongod.exe ...\src\mongo\db\service_entry_point_common.cpp(1041) mongo::anonymous namespace'::receivedCommands+0xa9
mongod.exe ...\src\mongo\db\service_entry_point_common.cpp(1324) mongo::ServiceEntryPointCommon::handleRequest+0x719
mongod.exe ...\src\mongo\db\service_entry_point_mongod.cpp(262) mongo::ServiceEntryPointMongod::handleRequest+0x3b
mongod.exe ...\src\mongo\transport\service_state_machine.cpp(441) mongo::ServiceStateMachine::_processMessage+0x1a6
mongod.exe ...\src\mongo\transport\service_state_machine.cpp(520) mongo::ServiceStateMachine::_runNextInGuard+0xc3
mongod.exe c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.16.27023\include\functional(16707566) std::_Func_impl_no_alloc<<lambda_b23af5efc3b61ab25bff0c3bcd13382b>,void>::_Do_call+0x5d
mongod.exe ...\src\mongo\transport\service_executor_synchronous.cpp(111) mongo::transport::ServiceExecutorSynchronous::schedule+0xfd
mongod.exe ...\src\mongo\transport\service_state_machine.cpp(564) mongo::ServiceStateMachine::_scheduleNextWithGuard+0xdc
mongod.exe ...\src\mongo\transport\service_state_machine.cpp(362) mongo::ServiceStateMachine::_sourceCallback+0xb5
mongod.exe ...\src\mongo\util\future_impl.h(236) mongo::future_details::call<<lambda_11453d3742ed318fceb22af47271f4f5> &,mongo::StatusWithmongo::Message >+0xc8
mongod.exe ...\src\mongo\util\future_impl.h(1170) mongo::future_details::FutureImplmongo::Message::generalImpl<<lambda_84dd0f151b2f4865f711936667f15dc2>,<lambda_cae9c6b0b0cce4baa010a32780d25278>,<lambda_1cf5694d79052a069e4bf7caff2ed043> >+0x5f
mongod.exe ...\src\mongo\transport\service_state_machine.cpp(516) mongo::ServiceStateMachine::_runNextInGuard+0x16f
mongod.exe c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.16.27023\include\functional(16707566) std::_Func_impl_no_alloc<<lambda_b23af5efc3b61ab25bff0c3bcd13382b>,void>::_Do_call+0x5d
mongod.exe ...\src\mongo\transport\service_executor_synchronous.cpp(125) <lambda_472996f9e6b00ec91d31b43a6cde81f7>::operator()+0x13d
mongod.exe c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.16.27023\include\thr\xthread(230) std::_LaunchPad<std::unique_ptr<std::tuple<std::function<void __cdecl(void)> >,std::default_delete<std::tuple<std::function<void __cdecl(void)> > > > >::_Go+0x72
mongod.exe c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.16.27023\include\thr\xthread(209) std::_Pad::_Call_func+0x9
ucrtbase.dll beginthreadex+0x142
KERNEL32.DLL BaseThreadInitThunk+0x14
2019-12-19T00:20:41.568+0500 I CONTROL [conn6] failed to open minidump file C:\Program Files\MongoDB\Server\4.2019-12-18T19-20-41.mdmp : Access is denied.
2019-12-19T00:20:41.578+0500 F CONTROL [conn6] *** immediate exit due to unhandled exception`

When I try to run after commenting the query it works fine, but for even a simple query server gets crashed.

@vkarpov15 vkarpov15 added this to the 5.8.2 milestone Dec 20, 2019
@vkarpov15 vkarpov15 added the needs repro script Maybe a bug, but no repro script. The issue reporter should create a script that demos the issue label Dec 20, 2019
@vkarpov15 vkarpov15 modified the milestones: 5.8.2, 5.8.3 Dec 20, 2019
@inampaki
Copy link
Author

inampaki commented Dec 21, 2019

o.query = {
                Status : {$ne : -1}                
		};
o.sort  = {"BatchIDs.ActionTakenOn" : -1};
o.scope = {
	finalizedBatchIDs   : [],
	distinctBatchIDsFromAllOrders : {},
	batchIDCounts       : 0,
	batchesToSkip       : (parseInt(req.body.skip) || 0),
	maxBatchesRequired  : parseInt(req.body.limit),
	getAllInProcessBatchOfAnOrder : getAllInProcessBatchOfAnOrder
};
o.map   = function(){
	var batchIDsOfThisOrder = getAllInProcessBatchOfAnOrder(this);
	batchIDsOfThisOrder.forEach(function(bID){
		distinctBatchIDsFromAllOrders[bID] = true;
		if((finalizedBatchIDs.length < maxBatchesRequired) && (finalizedBatchIDs.indexOf(bID) == -1)){
			if(Object.keys(distinctBatchIDsFromAllOrders).length > batchesToSkip){
				finalizedBatchIDs.push(bID);
			}
		}
	});
	emit("MAP", {BATCHES : finalizedBatchIDs, counts : Object.keys(distinctBatchIDsFromAllOrders).length});
};
o.reduce = function (k, v){
	return {BATCHES : finalizedBatchIDs, counts : Object.keys(distinctBatchIDsFromAllOrders).length};
};

Even this simple Query causing the crash while if I remove the query and pass empty object this same map reduce logic is working.

@vkarpov15
Copy link
Collaborator

The below script works fine for me:

'use strict';

const mongoose = require('mongoose');

run().catch(err => console.log(err));

async function run() {
  await mongoose.connect('mongodb://localhost:27017/test', {
    useNewUrlParser: true,
    useUnifiedTopology: true
  });
  await mongoose.connection.dropDatabase();

  const admin = mongoose.connection.db.admin();
  const { version } = await admin.serverStatus();
  console.log('Server version', version);
  
  const Model = mongoose.model('Test', mongoose.Schema({
    name: String
  }));
 
  await Model.create({ name: 'foo' });

  const o = {
    map: 'function() { emit(this.name, 1); }',
    reduce: function(k, vals) {
      return vals.length;
    }
  };
  const res = await Model.mapReduce(o);
  console.log(res.results);
}

Output:

$ node gh-8438.js 
Server version 4.2.2
[ { _id: 'foo', value: 1 } ]

In your stack trace, it looks like there's a permissions error trying to open C:\Program Files\MongoDB\Server\4.2019-12-18T19-20-41.mdmp - can you make sure your mongod process has permission to write to that file?

@vkarpov15 vkarpov15 added can't reproduce Mongoose devs have been unable to reproduce this issue. Close after 14 days of inactivity. and removed needs repro script Maybe a bug, but no repro script. The issue reporter should create a script that demos the issue labels Dec 21, 2019
@vkarpov15 vkarpov15 removed this from the 5.8.3 milestone Dec 21, 2019
@inampaki
Copy link
Author

As I stated that this map reduce was working fine for last more than two years and still works for any mongodb version below 4.2.2.
As you stated that it could be some permission related issue. I will re check this by installing mongodb some where else instead of Program Files and will get back to you.
Thanks for the support.

@Akta3d
Copy link

Akta3d commented Dec 23, 2019

Same problem here

on new PC install :
new ubuntu 18.04
mongodb 4.2.2
nodejs: 11.2.0
mongoose : 5.3.13
clone an existing working private project, npm install, node main.js

during a mapReduce call :

mongo_1  | 2019-12-23T21:17:55.613+0000 F  -        [conn5] Invalid access at address: 0
mongo_1  | 2019-12-23T21:17:55.633+0000 F  -        [conn5] Got signal: 11 (Segmentation fault).

I reproduce with this source :

'use strict';

const mongoose = require('mongoose');

run().catch(err => {
    console.log(err);
    process.exit(1);
});

async function run() {
    await mongoose.connect('mongodb://localhost:27017/test', {
        useNewUrlParser: true,
        useUnifiedTopology: true,
    });

    await mongoose.connection.dropDatabase();

    const admin = mongoose.connection.db.admin();
    const { version } = await admin.serverStatus();
    console.log('Server version', version);

    const Schema = new mongoose.Schema({
        portalId: {
            type: String,
            index: true,
        },
        name: {
            type: String,
            index: true,
        },
        reference: String,
        deleted: {
            type: Boolean,
            index: true,
        },
    });

    const Model = mongoose.model('Test', Schema);

    await Model.create({
        portalId: '1234',
        name: 'foo',
        reference: 'ref-1234',
        deleted: false,
    });

    const o = {
        scope: {},
        map: function () {
            emit(this._id, this);
        },
        reduce: function (k, vals) {
            return { data: vals };
        },
        query: {
            portalId: '1234',
            deleted: { $ne: true },
            // deleted: false
        },
    };

    const res = await Model.mapReduce(o);
    console.log(res.results);
    process.exit(1);
}

the problem is the line :
deleted: {$ne: true} in query object.
if I comment this line, all works.

@Akta3d
Copy link

Akta3d commented Dec 24, 2019

OK with 4.2.1

@vkarpov15 vkarpov15 added has repro script There is a repro script, the Mongoose devs need to confirm that it reproduces the issue and removed can't reproduce Mongoose devs have been unable to reproduce this issue. Close after 14 days of inactivity. labels Dec 26, 2019
@vkarpov15 vkarpov15 added this to the 5.8.4 milestone Dec 26, 2019
@vkarpov15 vkarpov15 modified the milestones: 5.8.4, 5.8.5 Jan 2, 2020
@vkarpov15 vkarpov15 added underlying library issue This issue is a bug with an underlying library, like the MongoDB driver or mongodb-core and removed has repro script There is a repro script, the Mongoose devs need to confirm that it reproduces the issue labels Jan 4, 2020
@vkarpov15 vkarpov15 removed this from the 5.8.5 milestone Jan 6, 2020
@vkarpov15
Copy link
Collaborator

I opened an issue on MongoDB's Jira, it looks like $ne is the culprit: https://jira.mongodb.org/projects/NODE/issues/NODE-2409?filter=allopenissues

@vkarpov15
Copy link
Collaborator

MongoDB server fixed this for 4.2.3: https://jira.mongodb.org/browse/SERVER-45177 . MongoDB server 4.2.3-rc1 is available, you should upgrade if you need this bug fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
underlying library issue This issue is a bug with an underlying library, like the MongoDB driver or mongodb-core
Projects
None yet
Development

No branches or pull requests

3 participants