Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-19693

Deadlock in map reduce when bailFromJS called

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 3.1.7
    • Affects Version/s: 3.1.6
    • Component/s: JavaScript
    • Labels:
      None
    • Fully Compatible
    • ALL
    • Hide
      t = db.query1;
      t.drop();
      t.insert({
      	"x" : []
      });
      
      m = function () {
          emit(this.x, 1);
      };
      
      r = function () {};
      
      res = t.mapReduce(m, r, {
          out: { inline: 5 },
          jsMode: true
      });
      
      Show
      t = db.query1; t.drop(); t.insert({ "x" : [] }); m = function () { emit( this .x, 1); }; r = function () {}; res = t.mapReduce(m, r, { out: { inline: 5 }, jsMode: true });
    • Platform 7 08/10/15

      The issue is being caused by Thread 2 obtaining the lock (proxyscope.cpp:240) and then waiting for _state to become "ImplResponse" before releasing the lock (proxyscope.cpp:248). Thread 15 is waiting to obtain the lock (proxyscope.cpp:240) so that it can eventually change the state to "ImplResponse" (proxyscope.cpp:318).

      Backtrace:

      * thread #2: tid = 0x1ea7be5, 0x00007fff967f0136 libsystem_kernel.dylib`__psynch_cvwait + 10
          frame #0: 0x00007fff967f0136 libsystem_kernel.dylib`__psynch_cvwait + 10
          frame #1: 0x00007fff938cde0c libsystem_pthread.dylib`_pthread_cond_wait + 693
          frame #2: 0x00007fff8d104c95 libc++.1.dylib`std::__1::condition_variable::wait(std::__1::unique_lock<std::__1::mutex>&) + 47
          frame #3: 0x000000010125ab61 mongod`void std::__1::condition_variable::wait<mongo::mozjs::MozJSProxyScope::runOnImplThread(std::__1::function<void ()>)::$_26>(this=0x000000010482b1d0, __lk=0x000000010a67ad98, __pred=mongo::mozjs::MozJSProxyScope::(anonymous class) at 0x000000010a67ad28)>)::$_26) + 65 at __mutex_base:340
          frame #4: 0x000000010125832b mongod`mongo::mozjs::MozJSProxyScope::runOnImplThread(this=0x000000010482b0e0, f=function<void ()> at 0x000000010a67af00)>) + 299 at proxyscope.cpp:248
          frame #5: 0x000000010125a588 mongod`mongo::mozjs::MozJSProxyScope::invoke(this=0x000000010482b0e0, func=1, argsObject=0x000000010482b720, recv=0x000000010a67b9e0, timeoutMs=0, ignoreReturn=true, readOnlyArgs=false, readOnlyRecv=false) + 264 at proxyscope.cpp:189
          frame #6: 0x0000000101206a64 mongod`mongo::PooledScope::invoke(this=0x0000000104838e10, func=1, args=0x000000010482b720, recv=0x000000010a67b9e0, timeoutMs=0, ignoreReturn=true, readOnlyArgs=false, readOnlyRecv=false) + 180 at engine.cpp:472
          frame #7: 0x00000001003a3156 mongod`mongo::mr::JSMapper::map(this=0x000000010482b6c0, o=0x000000010a67b9e0) + 230 at mr.cpp:118
          frame #8: 0x00000001003c2e19 mongod`mongo::mr::MapReduceCommand::run(this=0x00000001025d8cb0, txn=0x000000010a67f318, dbname=0x000000010a67d378, cmd=0x000000010a67d3a8, (null)=0, errmsg=0x000000010a67d390, result=0x000000010a67d4c0) + 8825 at mr.cpp:1407
        * frame #9: 0x0000000100487012 mongod`mongo::Command::run(this=0x00000001025d8cb0, txn=0x000000010a67f318, request=0x000000010a67e030, replyBuilder=0x000000010a67e0b0) + 2898 at dbcommands.cpp:1313
          frame #10: 0x000000010048619e mongod`mongo::Command::execCommand(txn=0x000000010a67f318, command=0x00000001025d8cb0, request=0x000000010a67e030, replyBuilder=0x000000010a67e0b0) + 3726 at dbcommands.cpp:1238
          frame #11: 0x00000001003359f0 mongod`mongo::runCommands(txn=0x000000010a67f318, request=0x000000010a67e030, replyBuilder=0x000000010a67e0b0) + 1952 at commands.cpp:495
          frame #12: 0x00000001006d7d79 mongod`mongo::(anonymous namespace)::receivedRpc(txn=0x000000010a67f318, client=0x0000000104c07650, dbResponse=0x000000010a67f390, message=0x000000010a67fb90) + 633 at instance.cpp:290
          frame #13: 0x00000001006d4729 mongod`mongo::assembleResponse(txn=0x000000010a67f318, m=0x000000010a67fb90, dbresponse=0x000000010a67f390, remote=0x000000010a67f2f8) + 2441 at instance.cpp:508
          frame #14: 0x0000000100018993 mongod`mongo::MyMessageHandler::process(this=0x000000010481b020, m=0x000000010a67fb90, port=0x0000000104c089b0) + 307 at db.cpp:165
          frame #15: 0x00000001012c72c7 mongod`mongo::PortMessageServer::handleIncomingMsg(arg=0x0000000104c089b0) + 2983 at message_server_port.cpp:229
          frame #16: 0x00000001012c564a mongod`void* std::__1::__thread_proxy<std::__1::tuple<std::__1::__bind<void* (*)(void*), mongo::(anonymous namespace)::MessagingPortWithHandler*> > >(void*) [inlined] decltype(__f=0x0000000104c03190, __args=0x0000000104c03198)(void*)>(fp)(std::__1::forward<mongo::(anonymous namespace)::MessagingPortWithHandler*&>(fp0))) std::__1::__invoke<void* (*&)(void*), mongo::(anonymous namespace)::MessagingPortWithHandler*&>(void* (*&&&)(void*), mongo::(anonymous namespace)::MessagingPortWithHandler*&&&) + 24 at __functional_base:413
          frame #17: 0x00000001012c5632 mongod`void* std::__1::__thread_proxy<std::__1::tuple<std::__1::__bind<void* (*)(void*), mongo::(anonymous namespace)::MessagingPortWithHandler*> > >(void*) [inlined] std::__1::__bind_return<void* (*)(void*), std::__1::tuple<mongo::(anonymous namespace)::MessagingPortWithHandler*>, std::__1::tuple<>, _is_valid_bind_return<void* (*)(void*), std::__1::tuple<mongo::(anonymous namespace)::MessagingPortWithHandler*>, std::__1::tuple<> >::value>::type std::__1::__apply_functor<void* (__f=0x0000000104c03190, __bound_args=0x0000000104c03198, (null)=__tuple_indices<0> at 0x000000010a67fea0, __args=0x000000010a67fe60)(void*), std::__1::tuple<mongo::(anonymous namespace)::MessagingPortWithHandler*>, 0ul, std::__1::tuple<> >(void* (*&)(void*), std::__1::tuple<mongo::(anonymous namespace)::MessagingPortWithHandler*>&, std::__1::__tuple_indices<0ul>, std::__1::tuple<>&&) + 40 at functional:2023
          frame #18: 0x00000001012c560a mongod`void* std::__1::__thread_proxy<std::__1::tuple<std::__1::__bind<void* (*)(void*), mongo::(anonymous namespace)::MessagingPortWithHandler*> > >(void*) [inlined] std::__1::__bind_return<void* (*)(void*), std::__1::tuple<mongo::(anonymous namespace)::MessagingPortWithHandler*>, std::__1::tuple<>, _is_valid_bind_return<void* (*)(void*), std::__1::tuple<mongo::(anonymous namespace)::MessagingPortWithHandler*>, std::__1::tuple<> >::value>::type std::__1::__bind<void* (this=0x0000000104c03190)(void*), mongo::(anonymous namespace)::MessagingPortWithHandler*>::operator()<>() + 38 at functional:2086
          frame #19: 0x00000001012c55e4 mongod`void* std::__1::__thread_proxy<std::__1::tuple<std::__1::__bind<void* (*)(void*), mongo::(anonymous namespace)::MessagingPortWithHandler*> > >(void*) [inlined] decltype(__f=0x0000000104c03190)(void*), mongo::(anonymous namespace)::MessagingPortWithHandler*> >(fp)(std::__1::forward<>(fp0))) std::__1::__invoke<std::__1::__bind<void* (*)(void*), mongo::(anonymous namespace)::MessagingPortWithHandler*> >(std::__1::__bind<void* (*)(void*), mongo::(anonymous namespace)::MessagingPortWithHandler*>&&) + 11 at __functional_base:413
          frame #20: 0x00000001012c55d9 mongod`void* std::__1::__thread_proxy<std::__1::tuple<std::__1::__bind<void* (*)(void*), mongo::(anonymous namespace)::MessagingPortWithHandler*> > >(void*) [inlined] void std::__1::__thread_execute<std::__1::__bind<void* (*)(void*), mongo::(anonymous namespace)::MessagingPortWithHandler*> >(__t=0x0000000104c03190, (null)=__tuple_indices<> at 0x000000010a67fe38)(void*), mongo::(anonymous namespace)::MessagingPortWithHandler*> >&, std::__1::__tuple_indices<>) + 25 at thread:332
          frame #21: 0x00000001012c55c0 mongod`void* std::__1::__thread_proxy<std::__1::tuple<std::__1::__bind<void* (*)(void*), mongo::(anonymous namespace)::MessagingPortWithHandler*> > >(__vp=0x0000000104c03190) + 368 at thread:342
          frame #22: 0x00007fff938cd268 libsystem_pthread.dylib`_pthread_body + 131
          frame #23: 0x00007fff938cd1e5 libsystem_pthread.dylib`_pthread_start + 176
          frame #24: 0x00007fff938cb41d libsystem_pthread.dylib`thread_start + 13
      
        thread #15: tid = 0x1ea7bfb, 0x00007fff967f0166 libsystem_kernel.dylib`__psynch_mutexwait + 10
          frame #0: 0x00007fff967f0166 libsystem_kernel.dylib`__psynch_mutexwait + 10
          frame #1: 0x00007fff938cb78a libsystem_pthread.dylib`_pthread_mutex_lock + 480
          frame #2: 0x00007fff8d139b6f libc++.1.dylib`std::__1::mutex::lock() + 9
          frame #3: 0x0000000101258261 mongod`mongo::mozjs::MozJSProxyScope::runOnImplThread(std::__1::function<void ()>) [inlined] std::__1::unique_lock<std::__1::mutex>::unique_lock(this=0x000000010a6f8448, __m=0x000000010482b150) + 97 at __mutex_base:108
          frame #4: 0x000000010125823d mongod`mongo::mozjs::MozJSProxyScope::runOnImplThread(std::__1::function<void ()>) [inlined] std::__1::unique_lock<std::__1::mutex>::unique_lock(this=0x000000010a6f8448, __m=0x000000010482b150) + 16 at __mutex_base:108
          frame #5: 0x000000010125822d mongod`mongo::mozjs::MozJSProxyScope::runOnImplThread(this=0x000000010482b0e0, f=function<void ()> at 0x000000010a6f8540)>) + 45 at proxyscope.cpp:240
          frame #6: 0x000000010125a8fe mongod`mongo::mozjs::MozJSProxyScope::injectNative(this=0x000000010482b0e0, field=0x000000010231e462, func=0x00000001003b0240, data=0x000000010a67ce90)(mongo::BSONObj const&, void*), void*) + 158 at proxyscope.cpp:211
          frame #7: 0x0000000101206acf mongod`mongo::PooledScope::injectNative(this=0x0000000104838e10, field=0x000000010231e462, func=0x00000001003b0240, data=0x000000010a67ce90)(mongo::BSONObj const&, void*), void*) + 95 at engine.cpp:486
          frame #8: 0x00000001003b01bc mongod`mongo::mr::State::switchMode(this=0x000000010a67ce90, jsMode=false) + 300 at mr.cpp:879
          frame #9: 0x00000001003b0697 mongod`mongo::mr::State::bailFromJS(this=0x000000010a67ce90) + 423 at mr.cpp:887
          frame #10: 0x00000001003b01ff mongod`mongo::mr::_bailFromJS(args=0x000000010a6f88a8, data=0x000000010a67ce90) + 47 at mr.cpp:1215
          frame #11: 0x000000010124fe0c mongod`mongo::mozjs::NativeFunctionInfo::call(cx=0x0000000104c0d460, args=CallArgs at 0x000000010a6f8998) + 444 at nativefunction.cpp:90
          frame #12: 0x000000010122e151 mongod`bool mongo::mozjs::smUtils::call<mongo::mozjs::NativeFunctionInfo>(cx=0x0000000104c0d460, argc=2, vp=0x000000010600af40) + 129 at wraptype.h:97
          frame #13: 0x00000001016f5bb3 mongod`js::Invoke(JSContext*, JS::CallArgs, js::MaybeConstruct) [inlined] js::CallJSNative(cx=0x0000000104c0d460, native=0x000000010122e0d0, args=0x000000010a6f8c90)(JSContext*, unsigned int, JS::Value*), JS::CallArgs const&) + 208 at jscntxtinlines.h:226
          frame #14: 0x00000001016f5ae3 mongod`js::Invoke(cx=0x0000000104c0d460, args=CallArgs at 0x000000010a6f8c90, construct=NO_CONSTRUCT) + 931 at Interpreter.cpp:491
          frame #15: 0x000000010171bbd9 mongod`Interpret(cx=0x0000000104c0d460, state=0x000000010a701c70) + 90921 at Interpreter.cpp:2602
          frame #16: 0x00000001017057b0 mongod`js::RunScript(cx=0x0000000104c0d460, state=0x000000010a701c70) + 816 at Interpreter.cpp:448
          frame #17: 0x00000001016f6073 mongod`js::Invoke(cx=0x0000000104c0d460, args=CallArgs at 0x000000010a701d10, construct=NO_CONSTRUCT) + 2355 at Interpreter.cpp:517
          frame #18: 0x00000001016dbf84 mongod`js::Invoke(cx=0x0000000104c0d460, thisv=0x000000010a702488, fval=0x000000010a7027c8, argc=0, argv=0x000000010a702858, rval=JS::MutableHandleValue at 0x000000010a702340) + 1460 at Interpreter.cpp:554
          frame #19: 0x0000000101cd39c4 mongod`JS_CallFunctionValue(cx=0x0000000104c0d460, obj=JS::HandleObject at 0x000000010a7024b8, fval=JS::HandleValue at 0x000000010a7024b0, args=0x000000010a702690, rval=JS::MutableHandleValue at 0x000000010a7024a8) + 260 at jsapi.cpp:4216
          frame #20: 0x000000010122924d mongod`JS::Call(cx=0x0000000104c0d460, thisObj=JS::HandleObject at 0x000000010a702508, fun=JS::HandleValue at 0x000000010a702500, args=0x000000010a702690, rval=JS::MutableHandleValue at 0x000000010a7024f8) + 77 at jsapi.h:3754
          frame #21: 0x000000010122b3e6 mongod`mongo::mozjs::MozJSImplScope::invoke(this=0x000000010684a600, func=1, argsObject=0x000000010482b720, recv=0x000000010a67b9e0, timeoutMs=0, ignoreReturn=true, readOnlyArgs=false, readOnlyRecv=false) + 1494 at implscope.cpp:517
          frame #22: 0x00000001012609f8 mongod`mongo::mozjs::MozJSProxyScope::invoke(this=0x0000000104c1cf38)::$_22::operator()() const + 120 at proxyscope.cpp:190
          frame #23: 0x00000001012608dc mongod`std::__1::__function::__func<mongo::mozjs::MozJSProxyScope::invoke(unsigned long long, mongo::BSONObj const*, mongo::BSONObj const*, int, bool, bool, bool)::$_22, std::__1::allocator<mongo::mozjs::MozJSProxyScope::invoke(unsigned long long, mongo::BSONObj const*, mongo::BSONObj const*, int, bool, bool, bool)::$_22>, void ()>::operator()() [inlined] decltype(__f=0x0000000104c1cf38)::$_22&>(fp)(std::__1::forward<>(fp0))) std::__1::__invoke<mongo::mozjs::MozJSProxyScope::invoke(unsigned long long, mongo::BSONObj const*, mongo::BSONObj const*, int, bool, bool, bool)::$_22&>(mongo::mozjs::MozJSProxyScope::invoke(unsigned long long, mongo::BSONObj const*, mongo::BSONObj const*, int, bool, bool, bool)::$_22&&&) + 60 at __functional_base:413
          frame #24: 0x00000001012608cb mongod`std::__1::__function::__func<mongo::mozjs::MozJSProxyScope::invoke(unsigned long long, mongo::BSONObj const*, mongo::BSONObj const*, int, bool, bool, bool)::$_22, std::__1::allocator<mongo::mozjs::MozJSProxyScope::invoke(unsigned long long, mongo::BSONObj const*, mongo::BSONObj const*, int, bool, bool, bool)::$_22>, void ()>::operator(this=0x0000000104c1cf30)() + 43 at functional:1370
          frame #25: 0x0000000100a4f841 mongod`std::__1::function<void ()>::operator(this=0x000000010482b190)() const + 129 at functional:1756
          frame #26: 0x0000000101257d39 mongod`mongo::mozjs::MozJSProxyScope::implThread(this=0x000000010482b0e0) + 1017 at proxyscope.cpp:307
          frame #27: 0x0000000101279e6d mongod`void* std::__1::__thread_proxy<std::__1::tuple<void (mongo::mozjs::MozJSProxyScope::*)(), mongo::mozjs::MozJSProxyScope*> >(void*) [inlined] decltype(__f=0x000000010482bf20, __a0=0x000000010482bf30)).*fp(std::__1::forward<>(fp1))) std::__1::__invoke<void (mongo::mozjs::MozJSProxyScope::*)(), mongo::mozjs::MozJSProxyScope*, void>(void (mongo::mozjs::MozJSProxyScope::*&&)(), mongo::mozjs::MozJSProxyScope*&&) + 136 at __functional_base:380
          frame #28: 0x0000000101279de5 mongod`void* std::__1::__thread_proxy<std::__1::tuple<void (mongo::mozjs::MozJSProxyScope::*)(), mongo::mozjs::MozJSProxyScope*> >(void*) [inlined] void std::__1::__thread_execute<void (mongo::mozjs::MozJSProxyScope::*)(), mongo::mozjs::MozJSProxyScope*, 1ul>(__t=0x000000010482bf20, (null)=__tuple_indices<1> at 0x000000010a702ea0)(), mongo::mozjs::MozJSProxyScope*>&, std::__1::__tuple_indices<1ul>) + 40 at thread:332
          frame #29: 0x0000000101279dbd mongod`void* std::__1::__thread_proxy<std::__1::tuple<void (mongo::mozjs::MozJSProxyScope::*)(), mongo::mozjs::MozJSProxyScope*> >(__vp=0x000000010482bf20) + 365 at thread:342
          frame #30: 0x00007fff938cd268 libsystem_pthread.dylib`_pthread_body + 131
          frame #31: 0x00007fff938cd1e5 libsystem_pthread.dylib`_pthread_start + 176
          frame #32: 0x00007fff938cb41d libsystem_pthread.dylib`thread_start + 13
      

      Only affects SpiderMonkey.

            Assignee:
            mira.carey@mongodb.com Mira Carey
            Reporter:
            j.delaney J Delaney
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: