"No event loop is running" error when building from Qt Creator 4.0

259 views
Skip to first unread message

Nathan Hourt

unread,
May 12, 2016, 12:08:39 PM5/12/16
to Cap'n Proto
I'm trying to update Qt Creator to 4.0 since that was recently released, but for reasons completely unfathomable to me, when I build and run my app in QtC 4, the app promptly crashes with the exception:

libc++abi.dylib: terminating with uncaught exception of type kj::ExceptionImpl: /tmp/capnp20151201-17482-15lmg1o/capnproto-c++-0.5.3/src/kj/async.c++:53: failed: expected loop != nullptr; No event loop is running on this thread.

stack: 0x10655b9b2 0x10655a697 0x1065a9b8e 0x1065271b7 0x1065287b9 0x1065241d4 0x1065240aa 0x106522f5b 0x10651eac5 0x10365b450 0x10365a7e2 0x1035fcdf5 0x1035fd13e 0x10539e72c 0x10539ce42 0x10539c2ea


I create a KJ event loop and wait scope, stack allocated, near the beginning of main() (code here). The exact same code builds and runs fine in QtC 3.6 with the same toolchain and environment. I note that I use qbs as my build system, and QtC 4 uses qbs 1.5, whereas 3.6 used 1.4, but I'm not sure what in the build system could cause this runtime error. My best guess is some kind of arcane linking quirk, but I have no idea what or how to fix it.


Any advice on how to troubleshoot this is welcome.

--
Nathan Hourt

The Truth will set you free

Kenton Varda

unread,
May 12, 2016, 1:53:33 PM5/12/16
to Nathan Hourt, Cap'n Proto
Hi Nathan,

It would probably help to decode that stack trace. If you build the app in debug mode (with -g, and without -O2) then you should get a symbolic stack trace. My guess is that somehow the call is being made on a different thread, or perhaps is being made at startup time before main() has been called, but the stack trace should make it clear.

-Kenton

--
You received this message because you are subscribed to the Google Groups "Cap'n Proto" group.
To unsubscribe from this group and stop receiving emails from it, send an email to capnproto+...@googlegroups.com.
Visit this group at https://groups.google.com/group/capnproto.

Nathan Hourt

unread,
May 12, 2016, 2:01:31 PM5/12/16
to Kenton Varda, Cap'n Proto
The kj stack trace is somewhat unhelpful (perhaps because kj is built in release mode?) but lldb gives a bit more insight (with very poor formatting for emails, sorry). As you can see, this is in the main thread, and it is well after the kj event loop and wait scope have been initialized:

1  __pthread_kill                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   0x7fff91926286

2  pthread_kill                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     0x7fff88cda9f9

3  abort                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            0x7fff922939ab

4  abort_message                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    0x7fff87eb4a21

5  default_terminate_handler()                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      0x7fff87edc9b9

6  _objc_terminate()                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                0x7fff8c3b47eb

7  std::__terminate(void ( *)())                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    0x7fff87eda0a1

8  __cxa_throw                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      0x7fff87ed9b30

9  kj::ExceptionCallback::RootExceptionCallback::onFatalException(kj::Exception&&)                                                                                                                                                                                                                                                                                                                                                                                                                                                  0x102face16    

10 kj::throwFatalException(kj::Exception&&)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         0x102fab32a    

11 kj::_::Debug::Fault::fatal()                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     0x102fa9582    

12 kj::(anonymous namespace)::currentEventLoop()                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    0x102f7612f    

13 kj::_::ChainPromiseNode::ChainPromiseNode(kj::Own<kj::_::PromiseNode>)                                                                                                                                                                                                                                                                                                                                                                                                                                                           0x102f77729    

14 kj::Own<kj::_::ChainPromiseNode> kj::heap<kj::_::ChainPromiseNode, kj::Own<kj::_::PromiseNode>>(kj::Own<kj::_::PromiseNode>&&)                                                                                                                                                                                                                                                                                                                                                                                                   0x102f73144    

15 kj::Promise<kj::_::JoinPromises_<kj::_::ReturnType_<capnp::LocalClient::call(unsigned long long, unsigned short, kj::Own<capnp::CallContextHook>&&)::'lambda'(), void>::Type>::Type> kj::Promise<void>::then<capnp::LocalClient::call(unsigned long long, unsigned short, kj::Own<capnp::CallContextHook>&&)::'lambda'(), kj::_::PropagateException>(capnp::LocalClient::call(unsigned long long, unsigned short, kj::Own<capnp::CallContextHook>&&)::'lambda'()&&, kj::_::PropagateException&&)                                 0x102f7301a    

16 capnp::LocalClient::call(unsigned long long, unsigned short, kj::Own<capnp::CallContextHook>&&)                                                                                                                                                                                                                                                                                                                                                                                                                                  0x102f71ecb    

17 capnp::LocalRequest::send()                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      0x102f6da35    

18 capnp::Request<Backend::GetContestFeedParams, Backend::GetContestFeedResults>::send()                                                                                                                                                                                                                                                                                                                                                                                                            capability.h                592 0x1000e23c0    

19 swv::BackendWrapper::getFeedGenerator()                                                                                                                                                                                                                                                                                                                                                                                                                                                          BackendWrapper.cpp          46  0x1000e1752    

20 swv::BackendWrapper::qt_static_metacall(QObject *, QMetaObject::Call, int, void * *)                                                                                                                                                                                                                                                                                                                                                                                                             moc_BackendWrapper.cpp      90  0x100083d65    

21 swv::BackendWrapper::qt_metacall(QMetaObject::Call, int, void * *)                                                                                                                                                                                                                                                                                                                                                                                                                               moc_BackendWrapper.cpp      142 0x1000840ae    

22 CallMethod(QQmlObjectOrGadget const&, int, int, int, int *, QV4::ExecutionEngine *, QV4::CallData *)                                                                                                                                                                                                                                                                                                                                                                                                                             0x101e0172c    

23 CallPrecise(QQmlObjectOrGadget const&, QQmlPropertyData const&, QV4::ExecutionEngine *, QV4::CallData *)                                                                                                                                                                                                                                                                                                                                                                                                                         0x101dffe42    

24 QV4::QObjectMethod::callInternal(QV4::CallData *) const                                                                                                                                                                                                                                                                                                                                                                                                                                                                          0x101dff2ea    

25 QV4::Runtime::callProperty(QV4::ExecutionEngine *, int, QV4::CallData *)                                                                                                                                                                                                                                                                                                                                                                                                                                                         0x101e148e2    

26 None                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             0x10c823a44    

27 QV4::SimpleScriptFunction::call(QV4::Managed const *, QV4::CallData *)                                                                                                                                                                                                                                                                                                                                                                                                                                                           0x101dabd29    

28 QV4::Runtime::callActivationProperty(QV4::ExecutionEngine *, int, QV4::CallData *)                                                                                                                                                                                                                                                                                                                                                                                                                                               0x101e13fef    

29 None                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             0x10c689698    

30 QV4::ScriptFunction::call(QV4::Managed const *, QV4::CallData *)                                                                                                                                                                                                                                                                                                                                                                                                                                                                 0x101dab415    

31 QV4::Runtime::callProperty(QV4::ExecutionEngine *, int, QV4::CallData *)                                                                                                                                                                                                                                                                                                                                                                                                                                                         0x101e148e2    

32 None                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             0x10c68839c    

33 QV4::SimpleScriptFunction::call(QV4::Managed const *, QV4::CallData *)                                                                                                                                                                                                                                                                                                                                                                                                                                                           0x101dabd29    

34 QV4::Runtime::callActivationProperty(QV4::ExecutionEngine *, int, QV4::CallData *)                                                                                                                                                                                                                                                                                                                                                                                                                                               0x101e13fef    

35 None                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             0x10c823f8e    

36 QV4::SimpleScriptFunction::call(QV4::Managed const *, QV4::CallData *)                                                                                                                                                                                                                                                                                                                                                                                                                                                           0x101dabd29    

37 QV4::QObjectSlotDispatcher::impl(int, QtPrivate::QSlotObjectBase *, QObject *, void * *, bool *)                                                                                                                                                                                                                                                                                                                                                                                                                                 0x101e0315e    

38 QMetaObject::activate(QObject *, int, int, void * *)                                                                                                                                                                                                                                                                                                                                                                                                                                                                             0x100e88dc1    

39 swv::VotingSystem::isReadyChanged()                                                                                                                                                                                                                                                                                                                                                                                                                                                              moc_VotingSystem.cpp        379 0x10008ea45    

40 QtPrivate::FunctorCall<QtPrivate::IndexesList<>, QtPrivate::List<>, void, void (swv::VotingSystem:: *)()>::call(void (swv::VotingSystem:: *)(), swv::VotingSystem *, void * *)                                                                                                                                                                                                                                                                                                                   qobjectdefs_impl.h          501 0x1000b66a3    

41 void QtPrivate::FunctionPointer<void (swv::VotingSystem:: *)()>::call<QtPrivate::List<>, void>(void (swv::VotingSystem:: *)(), swv::VotingSystem *, void * *)                                                                                                                                                                                                                                                                                                                                    qobjectdefs_impl.h          520 0x1000b6610    

42 QtPrivate::QSlotObject<void (swv::VotingSystem:: *)(), QtPrivate::List<>, void>::impl(int, QtPrivate::QSlotObjectBase *, QObject *, void * *, bool *)                                                                                                                                                                                                                                                                                                                                            qobject_impl.h              143 0x1000b652f    

43 QMetaObject::activate(QObject *, int, int, void * *)                                                                                                                                                                                                                                                                                                                                                                                                                                                                             0x100e88dc1    

44 swv::VotingSystem::adaptorReadyChanged(bool)                                                                                                                                                                                                                                                                                                                                                                                                                                                     moc_VotingSystem.cpp        399 0x10008eb3b    

45 QtPrivate::FunctorCall<QtPrivate::IndexesList<0>, QtPrivate::List<bool>, void, void (swv::VotingSystem:: *)(bool)>::call(void (swv::VotingSystem:: *)(bool), swv::VotingSystem *, void * *)                                                                                                                                                                                                                                                                                                      qobjectdefs_impl.h          501 0x1000b6393    

46 void QtPrivate::FunctionPointer<void (swv::VotingSystem:: *)(bool)>::call<QtPrivate::List<bool>, void>(void (swv::VotingSystem:: *)(bool), swv::VotingSystem *, void * *)                                                                                                                                                                                                                                                                                                                        qobjectdefs_impl.h          520 0x1000b62f0    

47 QtPrivate::QSlotObject<void (swv::VotingSystem:: *)(bool), QtPrivate::List<bool>, void>::impl(int, QtPrivate::QSlotObjectBase *, QObject *, void * *, bool *)                                                                                                                                                                                                                                                                                                                                    qobject_impl.h              143 0x1000b620f    

48 QMetaObject::activate(QObject *, int, int, void * *)                                                                                                                                                                                                                                                                                                                                                                                                                                                                             0x100e88dc1    

49 swv::ChainAdaptorWrapper::hasAdaptorChanged(bool)                                                                                                                                                                                                                                                                                                                                                                                                                                                moc_ChainAdaptorWrapper.cpp 234 0x100084fc8    

50 swv::ChainAdaptorWrapper::setAdaptor(kj::Own<BlockchainAdaptorInterface>)                                                                                                                                                                                                                                                                                                                                                                                                                        ChainAdaptorWrapper.cpp     45  0x1000e817b    

51 swv::VotingSystem::configureChainAdaptor(bool)                                                                                                                                                                                                                                                                                                                                                                                                                                                   VotingSystem.cpp            296 0x100095916    

52 swv::VotingSystem::qt_static_metacall(QObject *, QMetaObject::Call, int, void * *)                                                                                                                                                                                                                                                                                                                                                                                                               moc_VotingSystem.cpp        193 0x10008e062    

53 swv::VotingSystem::qt_metacall(QMetaObject::Call, int, void * *)                                                                                                                                                                                                                                                                                                                                                                                                                                 moc_VotingSystem.cpp        342 0x10008ed3e    

54 CallMethod(QQmlObjectOrGadget const&, int, int, int, int *, QV4::ExecutionEngine *, QV4::CallData *)                                                                                                                                                                                                                                                                                                                                                                                                                             0x101e01645    

55 CallPrecise(QQmlObjectOrGadget const&, QQmlPropertyData const&, QV4::ExecutionEngine *, QV4::CallData *)                                                                                                                                                                                                                                                                                                                                                                                                                         0x101e0005f    

56 QV4::QObjectMethod::callInternal(QV4::CallData *) const                                                                                                                                                                                                                                                                                                                                                                                                                                                                          0x101dffb74    

57 QV4::Runtime::callActivationProperty(QV4::ExecutionEngine *, int, QV4::CallData *)                                                                                                                                                                                                                                                                                                                                                                                                                                               0x101e13fef    

58 None                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             0x10c8269d5    

59 QV4::SimpleScriptFunction::call(QV4::Managed const *, QV4::CallData *)                                                                                                                                                                                                                                                                                                                                                                                                                                                           0x101dabd29    

60 QQmlJavaScriptExpression::evaluate(QV4::CallData *, bool *)                                                                                                                                                                                                                                                                                                                                                                                                                                                                      0x101ea1de8    

61 QQmlBoundSignalExpression::evaluate(void * *)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    0x101e49eed    

62 QQmlBoundSignal_callback(QQmlNotifierEndpoint *, void * *)                                                                                                                                                                                                                                                                                                                                                                                                                                                                       0x101e4a5f5    

63 QQmlNotifier::emitNotify(QQmlNotifierEndpoint *, void * *)                                                                                                                                                                                                                                                                                                                                                                                                                                                                       0x101e8328d    

64 QMetaObject::activate(QObject *, int, int, void * *)                                                                                                                                                                                                                                                                                                                                                                                                                                                                             0x100e88382    

65 QQmlObjectCreator::finalize(QQmlInstantiationInterrupt&)                                                                                                                                                                                                                                                                                                                                                                                                                                                                         0x101eb7dfd    

66 QQmlComponentPrivate::complete(QQmlEnginePrivate *, QQmlComponentPrivate::ConstructionState *)                                                                                                                                                                                                                                                                                                                                                                                                                                   0x101e3fe99    

67 QQmlComponentPrivate::completeCreate()                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           0x101e3e109    

68 QQmlComponent::create(QQmlContext *)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             0x101e3f872    

69 QQmlApplicationEnginePrivate::_q_finishLoad(QObject *)                                                                                                                                                                                                                                                                                                                                                                                                                                                                           0x101eaa2ff    

70 QQmlApplicationEngine::load(QUrl const&)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         0x101eaa8d2    

71 main                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             main.cpp                    109 0x1000c39bc    

72 start                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            0x100001964    



Kenton Varda

unread,
May 12, 2016, 2:09:55 PM5/12/16
to Nathan Hourt, Cap'n Proto
Hmm, I don't know, then. It seems like the threadlocal was clobbered somehow. I suppose that *could* have to do with linking in that the linker allocates threadlocal variables into the threadlocal segment...

-Kenton

--

Abhishek Balaji Radhakrishnan

unread,
Jun 20, 2016, 4:09:30 PM6/20/16
to Cap'n Proto, nat....@gmail.com
Hi Kenton,

When I spawn a new thread and put my server logic in the spawned thread, I get the same error. But from inside a forked process, it works! Is there any particular reason why? 

Ideally, I would like the server connection setup detached from the main thread by spawning it in a separate thread. This way the main thread is left standalone leaving it to perform some computations only when data is received from the pipe (through setting/unsetting a global variable flag, or using signals). Any idea how this can be accomplished?


Thanks.
...

Kenton Varda

unread,
Jun 24, 2016, 6:39:38 PM6/24/16
to Abhishek Balaji Radhakrishnan, Cap'n Proto, Nathan Hourt
Hi Abhishek,

If you are using Cap'n Proto RPC in a multi-threaded app, you'll need to make sure that each app has its own separate event loop, and that Cap'n Proto objects are never passed between threads. Inter-thread communication will need to happen over pipes or other low-level primitives. An event loop is tried to the thread that created it, so if you create an event loop in one thread, then trying to do RPC stuff that requires an event loop from some other thread (without giving it its own event loop), you'll have a problem.

fork() works because you're actually making a copy of the whole memory space including copying the event loop. However, fork()ing a process with a live event loop may produce some subtle issues on Linux since the two processes will end up pulling from the same epoll FD, so I don't recommend this.

-Kenton

--

Abhishek Balaji Radhakrishnan

unread,
Jun 25, 2016, 4:48:04 PM6/25/16
to Kenton Varda, Cap'n Proto, Nathan Hourt
Thanks, Kenton! That makes sense. 

-Abhishek


--
Abhishek

Reply all
Reply to author
Forward
0 new messages