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

[ios] [5.3.1] rare crash when going from background to foreground #127

Open
Overtorment opened this issue Oct 5, 2021 · 13 comments
Open
Labels
bug Something isn't working iOS work-in-progress

Comments

@Overtorment
Copy link

Description

I once experienced a crash when my app was in the background for a while, and I opened so it tried to go to foreground.
I immediately looked up our crash report on bugsnag:

NSInvalidArgumentException
TcpSockets.m:166
*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0]
Oct 5th, 2021, 11:44:31 UTC

STACKTRACE

CrashReporter Key:  57d0876ed81edcd073b616649639e4eae2160bcf
Hardware Model:     iPhone12,1
Process:            BlueWallet
Identifier:         io.bluewallet.bluewallet
Version:            6.2.9
Role:               Foreground
OS Version:         iOS 15.0


NSInvalidArgumentException: *** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0]

0  CoreFoundation    ___exceptionPreprocess
1  libobjc.A.dylib   _objc_exception_throw
2  CoreFoundation    __CFThrowFormattedException
3  CoreFoundation    -[__NSPlaceholderDictionary initWithObjects:forKeys:count:].cold.5
4  CoreFoundation    -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]
5  CoreFoundation    +[NSDictionary dictionaryWithObjects:forKeys:count:]
6  BlueWallet        -[TcpSockets onConnect:] (TcpSockets.m:166:24)
7  BlueWallet        -[TcpSocketClient socketDidSecure:] (TcpSocketClient.m:294:5)
8  BlueWallet        __42-[GCDAsyncSocket ssl_continueSSLHandshake]_block_invoke (GCDAsyncSocket.m:7344:5)
9  libdispatch.dylib __dispatch_call_block_and_release
10 libdispatch.dylib __dispatch_client_callout
11 libdispatch.dylib __dispatch_main_queue_callback_4CF
12 CoreFoundation    ___CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__
13 CoreFoundation    ___CFRunLoopRun
14 CoreFoundation    _CFRunLoopRunSpecific
15 GraphicsServices  _GSEventRunModal
16 UIKitCore         -[UIApplication _run]
17 UIKitCore         _UIApplicationMain
18 BlueWallet        main (main.m:14:12)

THREADS

Thread 0
0  CoreFoundation    ___exceptionPreprocess
1  libobjc.A.dylib   _objc_exception_throw
2  CoreFoundation    __CFThrowFormattedException
3  CoreFoundation    -[__NSPlaceholderDictionary initWithObjects:forKeys:count:].cold.5
4  CoreFoundation    -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]
5  CoreFoundation    +[NSDictionary dictionaryWithObjects:forKeys:count:]
6  BlueWallet        -[TcpSockets onConnect:] (TcpSockets.m:166:24)
7  BlueWallet        -[TcpSocketClient socketDidSecure:] (TcpSocketClient.m:294:5)
8  BlueWallet        __42-[GCDAsyncSocket ssl_continueSSLHandshake]_block_invoke (GCDAsyncSocket.m:7344:5)
9  libdispatch.dylib __dispatch_call_block_and_release
10 libdispatch.dylib __dispatch_client_callout
11 libdispatch.dylib __dispatch_main_queue_callback_4CF
12 CoreFoundation    ___CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__
13 CoreFoundation    ___CFRunLoopRun
14 CoreFoundation    _CFRunLoopRunSpecific
15 GraphicsServices  _GSEventRunModal
16 UIKitCore         -[UIApplication _run]
17 UIKitCore         _UIApplicationMain
18 BlueWallet        main (main.m:14:12)

Thread 1
0 libsystem_kernel.dylib  _mach_msg_trap
1 libsystem_kernel.dylib  _mach_msg
2 CoreFoundation          ___CFRunLoopServiceMachPort
3 CoreFoundation          ___CFRunLoopRun
4 CoreFoundation          _CFRunLoopRunSpecific
5 Foundation              -[NSRunLoop(NSRunLoop) runMode:beforeDate:]
6 Foundation              -[NSRunLoop(NSRunLoop) runUntilDate:]
7 UIKitCore               -[UIEventFetcher threadMain]
8 Foundation              ___NSThread__start__
9 libsystem_pthread.dylib __pthread_start

Thread 2
0 libsystem_kernel.dylib  _mach_msg_trap
1 libsystem_kernel.dylib  _mach_msg
2 libsystem_kernel.dylib  _thread_suspend
3 BlueWallet              ksmachexc_i_handleExceptions (BSG_KSCrashSentry_MachException.c:221:9)
4 libsystem_pthread.dylib __pthread_start

Thread 3
0 libsystem_kernel.dylib  _mach_msg_trap
1 libsystem_kernel.dylib  _mach_msg
2 BlueWallet              ksmachexc_i_handleExceptions (BSG_KSCrashSentry_MachException.c:228:28)
3 libsystem_pthread.dylib __pthread_start

Thread 4
0 libsystem_kernel.dylib  _semaphore_timedwait_trap
1 libdispatch.dylib       __dispatch_sema4_timedwait
2 libdispatch.dylib       __dispatch_semaphore_wait_slow
3 BlueWallet              -[BSGAppHangDetector detectAppHangs] (BSGAppHangDetector.m:121:13)
4 Foundation              ___NSThread__start__
5 libsystem_pthread.dylib __pthread_start

Thread 5
0 libsystem_kernel.dylib  _mach_msg_trap
1 libsystem_kernel.dylib  _mach_msg
2 CoreFoundation          ___CFRunLoopServiceMachPort
3 CoreFoundation          ___CFRunLoopRun
4 CoreFoundation          _CFRunLoopRunSpecific
5 BlueWallet              +[RCTCxxBridge runRunLoop] (RCTCxxBridge.mm:308:12)
6 Foundation              ___NSThread__start__
7 libsystem_pthread.dylib __pthread_start

Thread 6
0 libsystem_kernel.dylib  ___psynch_cvwait
1 libsystem_pthread.dylib __pthread_cond_wait
2 libc++.1.dylib          std::__1::condition_variable::__do_timed_wait(std::__1::unique_lock<std::__1::mutex>&, std::__1::chrono::time_point<std::__1::chrono::system_clock, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000000l> > >)
3 JavaScriptCore          bmalloc::Scavenger::threadRunLoop()
4 JavaScriptCore          bmalloc::Scavenger::threadEntryPoint(bmalloc::Scavenger*)
5 JavaScriptCore          void* std::__1::__thread_proxy<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct> >, void (*)(bmalloc::Scavenger*), bmalloc::Scavenger*> >(void*)
6 libsystem_pthread.dylib __pthread_start

Thread 7
0 libsystem_kernel.dylib  _mach_msg_trap
1 libsystem_kernel.dylib  _mach_msg
2 CoreFoundation          ___CFRunLoopServiceMachPort
3 CoreFoundation          ___CFRunLoopRun
4 CoreFoundation          _CFRunLoopRunSpecific
5 CoreFoundation          _CFRunLoopRun
6 CoreMotion              CLMotionActivity::isTypeInVehicle(CLMotionActivity::Type)
7 libsystem_pthread.dylib __pthread_start

Thread 8
0 libsystem_kernel.dylib  _mach_msg_trap
1 libsystem_kernel.dylib  _mach_msg
2 CoreFoundation          ___CFRunLoopServiceMachPort
3 CoreFoundation          ___CFRunLoopRun
4 CoreFoundation          _CFRunLoopRunSpecific
5 CFNetwork               __CFURLStorageSessionCopyIdentifier
6 Foundation              ___NSThread__start__
7 libsystem_pthread.dylib __pthread_start

Thread 9
0 libsystem_kernel.dylib  _mach_msg_trap
1 libsystem_kernel.dylib  _mach_msg
2 CoreFoundation          ___CFRunLoopServiceMachPort
3 CoreFoundation          ___CFRunLoopRun
4 CoreFoundation          _CFRunLoopRunSpecific
5 AudioSession            CADeprecated::GenericRunLoopThread::Entry(void*)
6 AudioSession            CADeprecated::CAPThread::Entry(CADeprecated::CAPThread*)
7 libsystem_pthread.dylib __pthread_start

Thread 10
0 libsystem_kernel.dylib  _mach_msg_trap
1 libsystem_kernel.dylib  _mach_msg
2 CoreFoundation          ___CFRunLoopServiceMachPort
3 CoreFoundation          ___CFRunLoopRun
4 CoreFoundation          _CFRunLoopRunSpecific
5 Foundation              -[NSRunLoop(NSRunLoop) runMode:beforeDate:]
6 BlueWallet              +[GCDAsyncSocket cfstreamThread:] (GCDAsyncSocket.m:7686:25)
7 Foundation              ___NSThread__start__
8 libsystem_pthread.dylib __pthread_start

Thread 11
0 libsystem_kernel.dylib  _select$DARWIN_EXTSN
1 CoreFoundation          ___CFSocketManager
2 libsystem_pthread.dylib __pthread_start

Thread 12
0 unknown file unknown method

Thread 13
0 libsystem_kernel.dylib  _kevent
1 BlueWallet              realm::_impl::ExternalCommitHelper::listen() (BlueWallet)
2 BlueWallet              void* std::__1::__thread_proxy<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct> >, realm::_impl::ExternalCommitHelper::ExternalCommitHelper(realm::_impl::RealmCoordinator&)::$_0> >(void*) (BlueWallet)
3 libsystem_pthread.dylib __pthread_start

Thread 14
0 unknown file unknown method

Thread 15
0 libsystem_blocks.dylib  __Block_copy
1 libnetwork.dylib        _nw_path_necp_update_evaluator
2 libnetwork.dylib        _nw_path_necp_check_for_updates
3 libdispatch.dylib       __dispatch_client_callout
4 libdispatch.dylib       __dispatch_continuation_pop
5 libdispatch.dylib       __dispatch_source_invoke
6 libdispatch.dylib       __dispatch_workloop_invoke
7 libdispatch.dylib       __dispatch_workloop_worker_thread
8 libsystem_pthread.dylib __pthread_wqthread

Thread 16
0 unknown file unknown method

Thread 17
0 unknown file unknown method

Thread 18
0 unknown file unknown method

Thread 19
0 BlueWallet              ___ZN5realm4util12_GLOBAL__N_122ReclaimerThreadStopperD2Ev_block_invoke (BlueWallet)
1 libdispatch.dylib       __dispatch_client_callout
2 libdispatch.dylib       __dispatch_continuation_pop
3 libdispatch.dylib       __dispatch_source_invoke
4 libdispatch.dylib       __dispatch_lane_serial_drain
5 libdispatch.dylib       __dispatch_lane_invoke
6 libdispatch.dylib       __dispatch_workloop_worker_thread
7 libsystem_pthread.dylib __pthread_wqthread

Thread 20
0  libsystem_kernel.dylib  ___ulock_wait
1  libdispatch.dylib       __dlock_wait
2  libdispatch.dylib       __dispatch_thread_event_wait_slow
3  libdispatch.dylib       ___DISPATCH_WAIT_FOR_QUEUE__
4  libdispatch.dylib       __dispatch_sync_f_slow
5  UIKitCore               ___37-[_UIRemoteKeyboards startConnection]_block_invoke_3
6  CoreFoundation          ___invoking___
7  CoreFoundation          -[NSInvocation invoke]
8  Foundation              ___NSXPCCONNECTION_IS_CALLING_OUT_TO_REPLY_BLOCK__
9  Foundation              -[NSXPCConnection _decodeAndInvokeReplyBlockWithEvent:sequence:replyInfo:]
10 Foundation              ___88-[NSXPCConnection _sendInvocation:orArguments:count:methodSignature:selector:withProxy:]_block_invoke_3
11 libxpc.dylib            __xpc_connection_reply_callout
12 libxpc.dylib            __xpc_connection_call_reply_async
13 libdispatch.dylib       __dispatch_client_callout3
14 libdispatch.dylib       __dispatch_mach_msg_async_reply_invoke
15 libdispatch.dylib       __dispatch_lane_serial_drain
16 libdispatch.dylib       __dispatch_lane_invoke
17 libdispatch.dylib       __dispatch_workloop_worker_thread
18 libsystem_pthread.dylib __pthread_wqthread

Thread 21
0 libsystem_kernel.dylib  _syscall_thread_switch
1 JavaScriptCore          JSC::Heap::resumeThePeriphery()
2 JavaScriptCore          JSC::Heap::finishChangingPhase(JSC::GCConductor)
3 JavaScriptCore          JSC::Heap::runFixpointPhase(JSC::GCConductor)
4 JavaScriptCore          JSC::Heap::runCurrentPhase(JSC::GCConductor, JSC::CurrentThreadState*)
5 JavaScriptCore          JSC::Heap::HeapThread::work()
6 JavaScriptCore          WTF::Detail::CallableWrapper<WTF::AutomaticThread::start(WTF::AbstractLocker const&)::$_0, void>::call()
7 JavaScriptCore          WTF::Thread::entryPoint(WTF::Thread::NewThreadContext*)
8 JavaScriptCore          WTF::wtfThreadEntryPoint(void*)
9 libsystem_pthread.dylib __pthread_start

Thread 22
0  JavaScriptCore          JSC::JSLexicalEnvironment::visitChildren(JSC::JSCell*, JSC::SlotVisitor&)
1  JavaScriptCore          JSC::SlotVisitor::drain(WTF::MonotonicTime)::$_3::operator()(JSC::MarkStackArray&) const
2  JavaScriptCore          JSC::SlotVisitor::drain(WTF::MonotonicTime)
3  JavaScriptCore          JSC::SlotVisitor::drainFromShared(JSC::SlotVisitor::SharedDrainMode, WTF::MonotonicTime)
4  JavaScriptCore          WTF::SharedTaskFunctor<void (), JSC::Heap::runBeginPhase(JSC::GCConductor)::$_18>::run()
5  JavaScriptCore          WTF::ParallelHelperClient::runTask(WTF::RefPtr<WTF::SharedTask<void ()>, WTF::RawPtrTraits<WTF::SharedTask<void ()> >, WTF::DefaultRefDerefTraits<WTF::SharedTask<void ()> > > const&)
6  JavaScriptCore          WTF::ParallelHelperPool::Thread::work()
7  JavaScriptCore          WTF::Detail::CallableWrapper<WTF::AutomaticThread::start(WTF::AbstractLocker const&)::$_0, void>::call()
8  JavaScriptCore          WTF::Thread::entryPoint(WTF::Thread::NewThreadContext*)
9  JavaScriptCore          WTF::wtfThreadEntryPoint(void*)
10 libsystem_pthread.dylib __pthread_start

Thread 23
0  JavaScriptCore          JSC::SlotVisitor::appendHiddenSlow(JSC::JSCell*, WTF::Dependency)
1  JavaScriptCore          JSC::Structure* JSC::JSObject::visitButterflyImpl<JSC::SlotVisitor>(JSC::SlotVisitor&)::{lambda(unsigned char)#1}::operator()(unsigned char) const
2  JavaScriptCore          JSC::JSObject::visitChildren(JSC::JSCell*, JSC::SlotVisitor&)
3  JavaScriptCore          JSC::SlotVisitor::drain(WTF::MonotonicTime)::$_3::operator()(JSC::MarkStackArray&) const
4  JavaScriptCore          JSC::SlotVisitor::drain(WTF::MonotonicTime)
5  JavaScriptCore          JSC::SlotVisitor::drainFromShared(JSC::SlotVisitor::SharedDrainMode, WTF::MonotonicTime)
6  JavaScriptCore          WTF::SharedTaskFunctor<void (), JSC::Heap::runBeginPhase(JSC::GCConductor)::$_18>::run()
7  JavaScriptCore          WTF::ParallelHelperClient::runTask(WTF::RefPtr<WTF::SharedTask<void ()>, WTF::RawPtrTraits<WTF::SharedTask<void ()> >, WTF::DefaultRefDerefTraits<WTF::SharedTask<void ()> > > const&)
8  JavaScriptCore          WTF::ParallelHelperPool::Thread::work()
9  JavaScriptCore          WTF::Detail::CallableWrapper<WTF::AutomaticThread::start(WTF::AbstractLocker const&)::$_0, void>::call()
10 JavaScriptCore          WTF::Thread::entryPoint(WTF::Thread::NewThreadContext*)
11 JavaScriptCore          WTF::wtfThreadEntryPoint(void*)
12 libsystem_pthread.dylib __pthread_start

Thread 24
0  JavaScriptCore          JSC::JSFinalObject::visitChildren(JSC::JSCell*, JSC::SlotVisitor&)
1  JavaScriptCore          JSC::SlotVisitor::drain(WTF::MonotonicTime)::$_3::operator()(JSC::MarkStackArray&) const
2  JavaScriptCore          JSC::SlotVisitor::drain(WTF::MonotonicTime)
3  JavaScriptCore          JSC::SlotVisitor::drainFromShared(JSC::SlotVisitor::SharedDrainMode, WTF::MonotonicTime)
4  JavaScriptCore          WTF::SharedTaskFunctor<void (), JSC::Heap::runBeginPhase(JSC::GCConductor)::$_18>::run()
5  JavaScriptCore          WTF::ParallelHelperClient::runTask(WTF::RefPtr<WTF::SharedTask<void ()>, WTF::RawPtrTraits<WTF::SharedTask<void ()> >, WTF::DefaultRefDerefTraits<WTF::SharedTask<void ()> > > const&)
6  JavaScriptCore          WTF::ParallelHelperPool::Thread::work()
7  JavaScriptCore          WTF::Detail::CallableWrapper<WTF::AutomaticThread::start(WTF::AbstractLocker const&)::$_0, void>::call()
8  JavaScriptCore          WTF::Thread::entryPoint(WTF::Thread::NewThreadContext*)
9  JavaScriptCore          WTF::wtfThreadEntryPoint(void*)
10 libsystem_pthread.dylib __pthread_start

Thread 25
0  JavaScriptCore          JSC::SlotVisitor::appendHiddenSlow(JSC::JSCell*, WTF::Dependency)
1  JavaScriptCore          JSC::JSFinalObject::visitChildren(JSC::JSCell*, JSC::SlotVisitor&)
2  JavaScriptCore          JSC::SlotVisitor::drain(WTF::MonotonicTime)::$_3::operator()(JSC::MarkStackArray&) const
3  JavaScriptCore          JSC::SlotVisitor::drain(WTF::MonotonicTime)
4  JavaScriptCore          JSC::SlotVisitor::drainFromShared(JSC::SlotVisitor::SharedDrainMode, WTF::MonotonicTime)
5  JavaScriptCore          WTF::SharedTaskFunctor<void (), JSC::Heap::runBeginPhase(JSC::GCConductor)::$_18>::run()
6  JavaScriptCore          WTF::ParallelHelperClient::runTask(WTF::RefPtr<WTF::SharedTask<void ()>, WTF::RawPtrTraits<WTF::SharedTask<void ()> >, WTF::DefaultRefDerefTraits<WTF::SharedTask<void ()> > > const&)
7  JavaScriptCore          WTF::ParallelHelperPool::Thread::work()
8  JavaScriptCore          WTF::Detail::CallableWrapper<WTF::AutomaticThread::start(WTF::AbstractLocker const&)::$_0, void>::call()
9  JavaScriptCore          WTF::Thread::entryPoint(WTF::Thread::NewThreadContext*)
10 JavaScriptCore          WTF::wtfThreadEntryPoint(void*)
11 libsystem_pthread.dylib __pthread_start

Thread 26
0  JavaScriptCore          JSC::JSFinalObject::visitChildren(JSC::JSCell*, JSC::SlotVisitor&)
1  JavaScriptCore          JSC::SlotVisitor::drain(WTF::MonotonicTime)::$_3::operator()(JSC::MarkStackArray&) const
2  JavaScriptCore          JSC::SlotVisitor::drain(WTF::MonotonicTime)
3  JavaScriptCore          JSC::SlotVisitor::drainFromShared(JSC::SlotVisitor::SharedDrainMode, WTF::MonotonicTime)
4  JavaScriptCore          WTF::SharedTaskFunctor<void (), JSC::Heap::runBeginPhase(JSC::GCConductor)::$_18>::run()
5  JavaScriptCore          WTF::ParallelHelperClient::runTask(WTF::RefPtr<WTF::SharedTask<void ()>, WTF::RawPtrTraits<WTF::SharedTask<void ()> >, WTF::DefaultRefDerefTraits<WTF::SharedTask<void ()> > > const&)
6  JavaScriptCore          WTF::ParallelHelperPool::Thread::work()
7  JavaScriptCore          WTF::Detail::CallableWrapper<WTF::AutomaticThread::start(WTF::AbstractLocker const&)::$_0, void>::call()
8  JavaScriptCore          WTF::Thread::entryPoint(WTF::Thread::NewThreadContext*)
9  JavaScriptCore          WTF::wtfThreadEntryPoint(void*)
10 libsystem_pthread.dylib __pthread_start

Steps to reproduce

Steps to reproduce the behavior:

  1. keep the app in the background for a while
  2. open the app
  3. small chance of an immediate crash

Screenshots
If applicable, add screenshots to help explain your problem.

Relevant information

OS ios 15.0
react-native 0.64.2
react-native-tcp-socket 5.3.1
@Overtorment Overtorment added the bug Something isn't working label Oct 5, 2021
@Overtorment
Copy link
Author

screenshots from bugsnag:

image
image

@Overtorment
Copy link
Author

image

@Rapsssito
Copy link
Owner

@Overtorment, thanks for the feedback! iOS has a very special way of dealing with sockets when an app is in the background, which may be the root cause of this issue. A temporary workaround would be to close all sockets when the app is going to the background. I will take a look at your error trace and improve the module error handling for this kind of situations.

I will close this issue as soon as this problem is fixed.

@Rapsssito
Copy link
Owner

@Overtorment, could you tell me if you are using an HTTPS connection and if you are sending data when the app is in the background?

@Overtorment
Copy link
Author

yes, connection is https.
as for background, network module is not aware of such thing. i.e. state change is not handled in any way (at least not in the networking module)

@liuguanlin
Copy link

liuguanlin commented Feb 23, 2023

image
Same crash,Do you have a solution

@Rapsssito
Copy link
Owner

@liuguanlin, I am sorry but I was not able to reproduce this issue. Could you create a minimal reproducible code example?

@liuguanlin
Copy link

@liuguanlin, I am sorry but I was not able to reproduce this issue. Could you create a minimal reproducible code example?

Bugly collected it, but I didn't reproduce it myself

@siarheipashkevich
Copy link

image

I've the same issue also on iOS

@sergeushenecz
Copy link

I have same issue.

@sergeushenecz
Copy link

sergeushenecz commented Apr 7, 2023

@Rapsssito Could you please check?

@siarheipashkevich
Copy link

siarheipashkevich commented Apr 9, 2023

@Rapsssito for reproducing this issue you need:

  • create server in the app
  • move app to the background
  • connect to the server (when the app in background)
  • open the app (there is error is happened and app is crashed (closed))

@zameschua
Copy link

I managed to reliably reproduce the above issue

  1. create server
  2. background the app
  3. connect to server while server app is backgrounded
  4. open the app
image

Not 100% sure if it's a related issue, but I managed to get a NSInvalidArgumentException on the TCP server by repeatedly connecting and disconnecting to a TCP server from another TCP socket

image image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working iOS work-in-progress
Projects
None yet
Development

No branches or pull requests

6 participants