socketio / socket.io-client-swift

Other
5.22k stars 844 forks source link

iPhone 5 - dataLength = bytes[0].bigEndian EXC_BAD_ACCESS (code=EXC_ARM_DA_ALIGN, address=0x1762220a) #243

Closed civocr closed 8 years ago

civocr commented 8 years ago

Hi,

I've just swapped out my old socket.io implementation to use the swift lib in an ObjC project.

On simulator and iPod the implementation works fine but as soon as I run it on iPhone 5 (iOS 9.1) it crashes on a big dataset being returned from the server.

Socket_IO_Client_Swift was compiled with optimization - stepping may behave oddly; variables may not be available.
(lldb) bt
* thread #7: tid = 0xf4ce2, 0x0083fd2c Socket_IO_Client_Swift`Socket_IO_Client_Swift.WebSocket.(buffer=(_rawValue = 0x17622208), bufferLen=4096, self=0x1a1b8f80) (Socket_IO_Client_Swift.WebSocket)(Swift.UnsafePointer<Swift.UInt8>, bufferLen : Swift.Int) -> () + 7924 at WebSocket.swift:493, queue = 'com.apple.root.default-qos', stop reason = EXC_BAD_ACCESS (code=EXC_ARM_DA_ALIGN, address=0x1762220a)
  * frame #0: 0x0083fd2c Socket_IO_Client_Swift`Socket_IO_Client_Swift.WebSocket.(buffer=(_rawValue = 0x17622208), bufferLen=4096, self=0x1a1b8f80) (Socket_IO_Client_Swift.WebSocket)(Swift.UnsafePointer<Swift.UInt8>, bufferLen : Swift.Int) -> () + 7924 at WebSocket.swift:493 [opt]
    frame #1: 0x0083d6d4 Socket_IO_Client_Swift`Socket_IO_Client_Swift.WebSocket.(processInputStream in _36A71CEA378D31C7E60930417F41D52F) (Socket_IO_Client_Swift.WebSocket)() -> () + 148 at WebSocket.swift:353 [opt]
    frame #2: 0x0083d640 Socket_IO_Client_Swift`Socket_IO_Client_Swift.WebSocket.(self=0x1a1b8f80) (Socket_IO_Client_Swift.WebSocket)() -> () + 2280 at WebSocket.swift:336 [opt]
    frame #3: 0x00847a74 Socket_IO_Client_Swift`function signature specialization <Arg[0] = Owned To Guaranteed> of Socket_IO_Client_Swift.WebSocket.stream (aStream=<unavailable>, eventCode=<unavailable>, self=0x1a1b8f80)(__ObjC.NSStream, handleEvent : __C.NSStreamEvent) -> () + 4932 at WebSocket.swift:289 [opt]
    frame #4: 0x0083cd44 Socket_IO_Client_Swift`@objc Socket_IO_Client_Swift.WebSocket.stream (Socket_IO_Client_Swift.WebSocket)(__ObjC.NSStream, handleEvent : __C.NSStreamEvent) -> () + 52 at WebSocket.swift:0 [opt]
    frame #5: 0x255e79aa CoreFoundation`_signalEventSync + 146
    frame #6: 0x255f20f8 CoreFoundation`_cfstream_solo_signalEventSync + 208
    frame #7: 0x255e7638 CoreFoundation`_CFStreamSignalEvent + 320
    frame #8: 0x24e782e8 CFNetwork`SocketStream::dispatchSignalFromSocketCallbackUnlocked(SocketStreamSignalHolder*) + 40
    frame #9: 0x24e77fc0 CFNetwork`SocketStream::socketCallback(__CFSocket*, unsigned long, __CFData const*, void const*) + 188
    frame #10: 0x24e77ed2 CFNetwork`SocketStream::_SocketCallBack_stream(__CFSocket*, unsigned long, __CFData const*, void const*, void*) + 58
    frame #11: 0x2563c4f6 CoreFoundation`__CFSocketPerformV0 + 818
    frame #12: 0x256387c6 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 14
    frame #13: 0x256383b6 CoreFoundation`__CFRunLoopDoSources0 + 454
    frame #14: 0x2563671e CoreFoundation`__CFRunLoopRun + 806
    frame #15: 0x255890d8 CoreFoundation`CFRunLoopRunSpecific + 516
    frame #16: 0x25588ecc CoreFoundation`CFRunLoopRunInMode + 108
    frame #17: 0x2637b88c Foundation`-[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 268
    frame #18: 0x00845594 Socket_IO_Client_Swift`function signature specialization <Arg[0] = Owned To Guaranteed> of Socket_IO_Client_Swift.WebSocket.(data=<unavailable>, port=<unavailable>, self=0x1a1b8f80) (Socket_IO_Client_Swift.WebSocket)(__ObjC.NSData, Swift.Int) -> () + 4720 at WebSocket.swift:268 [opt]
    frame #19: 0x0083ccc4 Socket_IO_Client_Swift`Socket_IO_Client_Swift.WebSocket.(self=0x1a1b8f80) (Socket_IO_Client_Swift.WebSocket)() -> () + 3876 at WebSocket.swift:191 [opt]
    frame #20: 0x0084a248 Socket_IO_Client_Swift`Socket_IO_Client_Swift.WebSocket.(self=0x1a1b95cc) -> () -> ()).(closure #2) + 92 at WebSocket.swift:136 [opt]
    frame #21: 0x00a0fd16 libdispatch.dylib`_dispatch_call_block_and_release + 10
    frame #22: 0x00a1c06e libdispatch.dylib`_dispatch_root_queue_drain + 1802
    frame #23: 0x00a1b960 libdispatch.dylib`_dispatch_worker_thread3 + 100
    frame #24: 0x375f0e0c libsystem_pthread.dylib`_pthread_wqthread + 1024
    frame #25: 0x375f09fc libsystem_pthread.dylib`start_wqthread + 8
nuclearace commented 8 years ago

Does it only happen if you compile the library with optimizations? If so see https://github.com/daltoniam/Starscream/issues/77

civocr commented 8 years ago

Optimisations for Debug are set to None [-O0]

I tried adding SWIFT_OPTIMIZATION_LEVEL = "-Onone" to my build settings but still crashes when a big dataset is returned over the socket

nuclearace commented 8 years ago

How did you install the library? It could be the library is already compiled with optimizations

civocr commented 8 years ago

cocopods

platform :ios, '8.3' use_frameworks!

pod 'Socket.IO-Client-Swift', '~> 4.1.2'

nuclearace commented 8 years ago

I really have no idea if CocoaPods would compile the library with optimizations separately from your build settings. The only way to test would be to manually add the Swift files and compile them like that.

civocr commented 8 years ago

sorry this was my mistake. I was trying to set my project to swift optimisation none. I changed the socket pod project to none and it works