snej / MYNetwork

Mooseyard Networking library: Cocoa utilities, including a generic TCP server/client, plus the reference implementation of the message-oriented BLIP protocol. (This is a mirror of the Mercurial repository at https://bitbucket.org/snej/mynetwork)
27 stars 9 forks source link

TCPStream crash on iOS ARM64 device #9

Closed ghmrs356 closed 6 years ago

ghmrs356 commented 11 years ago

Using on iPhone 5s for the first time, crashes in TCPStream.m in TCPStream -disconnect at line 122. Any idea what is going on?

- (void) disconnect
{
    if( _stream ) {
        LogTo(TCP,@"Disconnect %@",self);
        _stream.delegate = nil;
        [_stream close];
        _stream = nil;
    }
    if( _conn ) {
        [_conn _streamDisconnected: self];
        _conn = nil;  <----------- crashes here
    }
}
Thread 1, Queue : com.apple.main-thread
#0  0x00000001985b5d6c in objc_object::release() ()
#1  0x00000001003700fc in -[TCPStream disconnect] at /Users/markus/Projects/SOFramework/MYNetwork/TCP/TCPStream.m:122
#2  0x000000010035e464 in -[BLIPWriter disconnect] at /Users/markus/Projects/SOFramework/MYNetwork/BLIP/BLIPWriter.m:32
#3  0x000000010036ae38 in -[TCPConnection _streamCanClose:] at /Users/markus/Projects/SOFramework/MYNetwork/TCP/TCPConnection.m:413
#4  0x000000010037025c in -[TCPStream close] at /Users/markus/Projects/SOFramework/MYNetwork/TCP/TCPStream.m:137
#5  0x0000000100370e18 in -[TCPStream stream:handleEvent:] at /Users/markus/Projects/SOFramework/MYNetwork/TCP/TCPStream.m:235
#6  0x000000018c5fc62c in _signalEventSync ()
#7  0x000000018c608754 in _cfstream_solo_signalEventSync ()
#8  0x000000018c5fc184 in _CFStreamSignalEvent ()
#9  0x000000018c1ce8f4 in CoreReadStreamCFStreamSupport::coreStreamReadEvent(__CoreReadStream*, unsigned long) ()
#10 0x000000018c1ce85c in CoreReadStreamClient::coreStreamEventsAvailable(unsigned long) ()
#11 0x000000018c2aca9c in CoreStreamBase::_callClientNow(CoreStreamClient*) ()
#12 0x000000018c1ce5d8 in CoreStreamBase::_streamSetEventAndScheduleDelivery(unsigned long, unsigned char) ()
#13 0x000000018c1ce370 in SocketStream::dispatchSignalFromSocketCallbackUnlocked(SocketStreamSignalHolder*) ()
#14 0x000000018c1cdbec in SocketStream::socketCallback(__CFSocket*, unsigned long, __CFData const*, void const*) ()
#15 0x000000018c1cdadc in SocketStream::_SocketCallBack_stream(__CFSocket*, unsigned long, __CFData const*, void const*, void*) ()
#16 0x000000018c64a26c in __CFSocketPerformV0 ()
#17 0x000000018c64777c in __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ ()
#18 0x000000018c646ad8 in __CFRunLoopDoSources0 ()
#19 0x000000018c644d70 in __CFRunLoopRun ()
#20 0x000000018c585b78 in CFRunLoopRunSpecific ()
#21 0x0000000191fa7830 in GSEventRunModal ()
#22 0x000000018f5c305c in UIApplicationMain ()
#23 0x00000001000cd304 in main at /Users/markus/Projects/rubiTrack-to-Go/src/app/main.m:44
#24 0x0000000198b8baa0 in start ()
Thread 2, Queue : com.apple.libdispatch-manager
#0  0x0000000198c6dac8 in kevent64 ()
#1  0x0000000198b793d8 in _dispatch_mgr_invoke ()
#2  0x0000000198b71d88 in _dispatch_mgr_thread ()
Thread 5, Queue : (null)
#0  0x0000000198d057a4 in start_wqthread ()
Thread 6 com.apple.CFSocket.private, Queue : (null)
#0  0x0000000198c8676c in select$DARWIN_EXTSN ()
#1  0x000000018c64bc2c in __CFSocketManager ()
#2  0x0000000198d081b0 in _pthread_body ()
#3  0x0000000198d08108 in _pthread_start ()
#4  0x0000000198d057b0 in thread_start ()
Thread 7 com.apple.NSURLConnectionLoader, Queue : (null)
#0  0x0000000198c6dcc0 in mach_msg_trap ()
#1  0x0000000198c6db2c in mach_msg ()
#2  0x000000018c646cac in __CFRunLoopServiceMachPort ()
#3  0x000000018c644e3c in __CFRunLoopRun ()
#4  0x000000018c585b78 in CFRunLoopRunSpecific ()
#5  0x000000018d16ea1c in +[NSURLConnection(Loader) _resourceLoadLoop:] ()
#6  0x000000018d1fc990 in __NSThread__main__ ()
#7  0x0000000198d081b0 in _pthread_body ()
#8  0x0000000198d08108 in _pthread_start ()
Thread 8, Queue : UIDocument File Access
#0  0x0000000198c6dcfc in semaphore_wait_trap ()
#1  0x0000000198b77c08 in _dispatch_semaphore_wait_slow ()
#2  0x000000018d299674 in -[NSFileCoordinator(NSPrivate) _blockOnAccessClaim:] ()
#3  0x000000018d29a1c0 in -[NSFileCoordinator(NSPrivate) _coordinateWritingItemAtURL:options:error:byAccessor:] ()
#4  0x000000018d2984ec in -[NSFileCoordinator coordinateWritingItemAtURL:options:error:byAccessor:] ()
#5  0x000000018fa7f90c in -[UIDocument _coordinateWritingItemAtURL:error:byAccessor:] ()
#6  0x000000018fa801a0 in __59-[UIDocument saveToURL:forSaveOperation:completionHandler:]_block_invoke ()
#7  0x0000000198b7043c in _dispatch_call_block_and_release ()
#8  0x0000000198b703fc in _dispatch_client_callout ()
#9  0x0000000198b766f0 in _dispatch_queue_drain ()
#10 0x0000000198b72890 in _dispatch_queue_invoke ()
#11 0x0000000198b773a4 in _dispatch_root_queue_drain ()
#12 0x0000000198b77634 in _dispatch_worker_thread2 ()
#13 0x0000000198d05918 in _pthread_wqthread ()
Thread 9, Queue : (null)
#0  0x0000000198c86e74 in __workq_kernreturn ()
#1  0x0000000198d0592c in _pthread_wqthread ()
Thread 11, Queue : com.apple.root.default-priority
#0  0x0000000198c6dcfc in semaphore_wait_trap ()
#1  0x0000000198b77c08 in _dispatch_semaphore_wait_slow ()
#2  0x0000000198d24700 in xpc_connection_send_message_with_reply_sync ()
#3  0x000000018f52845c in _reach_server_target_remove ()
#4  0x000000018f5283a0 in __SCNetworkReachabilityServer_targetRemove ()
#5  0x000000018f506c18 in __SCNetworkReachabilityDeallocate ()
#6  0x000000018c581ee4 in CFRelease ()
#7  0x0000000198b703fc in _dispatch_client_callout ()
#8  0x0000000198b773f8 in _dispatch_root_queue_drain ()
#9  0x0000000198b77634 in _dispatch_worker_thread2 ()
#10 0x0000000198d05918 in _pthread_wqthread ()
#11 0x0000000198d057a8 in start_wqthread ()
Thread 12, Queue : (null)
#0  0x0000000198c86e74 in __workq_kernreturn ()
GoannaGuy commented 10 years ago

I just ran into this myself today on 64bit OSX. It manifested for me when I had a server running with a client that connected/disconnected/reconnected rapidly.

It appears to be an ARC related issue. I have a fix for it on my local machine. I'll create a fork and issue a pull request to the maintainer.

ghmrs356 commented 10 years ago

That explains why moving my local version from ARC back to manual reference counting fixed the issue.

GoannaGuy commented 10 years ago

Pull request can be found in issue #11

snej commented 10 years ago

You closed that pull request saying that it didn't fix the issue after all. So this is still unexplained?

GoannaGuy commented 10 years ago

Jens,

Actually, I opened a subsequent pull request later yesterday that does appear to fix it completely, which contains the fix from the initial pull request, plus a couple more changes.

-=- John

John Turnipseed johnt@me.com

On Feb 21, 2014, at 11:16:53 AM, Jens Alfke notifications@github.com wrote:

You closed that pull request saying that it didn't fix the issue after all. So this is still unexplained?

— Reply to this email directly or view it on GitHub.