socketio / socket.io-client-swift

Other
5.22k stars 844 forks source link

closeWithFast Crash on Mavericks #109

Closed EduardoAlberti closed 9 years ago

EduardoAlberti commented 9 years ago

When the socket is trying to reconnect, a call to [socket closeWithFast:NO] makes the app crash.

Example app link: http://d.pr/f/1i2Xf/5ywClxr6

Crash report:

Process:         swiftTest [3295]
Path:            /Users/USER/Desktop/swiftTest.app/Contents/MacOS/swiftTest
Identifier:      com.convo.swiftTest
Version:         1.0 (1)
Code Type:       X86-64 (Native)
Parent Process:  launchd [178]
Responsible:     swiftTest [3295]
User ID:         501

Date/Time:       2015-07-03 09:48:39.870 -0400
OS Version:      Mac OS X 10.9.5 (13F34)
Report Version:  11
Anonymous UUID:  85839A92-CA0A-ECD8-380C-1C290B32C6D1

Crashed Thread:  1  Dispatch queue: com.apple.NSURLSession-work

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x0000000000000008

VM Regions Near 0x8:
--> 
    __TEXT                 000000010c3d4000-000000010c447000 [  460K] r-x/rwx SM=COW  /Users/USER/Desktop/swiftTest.app/Contents/MacOS/swiftTest

Thread 0:: Dispatch queue: com.apple.main-thread
0   libobjc.A.dylib                 0x00007fff9585d185 class_respondsToSelector + 32
1   libobjc.A.dylib                 0x00007fff95872e81 -[NSObject respondsToSelector:] + 38
2   com.apple.AppKit                0x00007fff948bef4e -[NSWindow fieldEditor:forObject:] + 139
3   com.apple.AppKit                0x00007fff94804571 -[NSControl currentEditor] + 49
4   com.apple.AppKit                0x00007fff9492a52d -[NSControl _shouldShowFirstResponderForCell:] + 91
5   com.apple.AppKit                0x00007fff94a411ad -[NSControl mouseDown:] + 818
6   com.apple.AppKit                0x00007fff949c2a58 -[NSWindow sendEvent:] + 11296
7   com.apple.AppKit                0x00007fff949615d4 -[NSApplication sendEvent:] + 2021
8   com.apple.AppKit                0x00007fff947b19f9 -[NSApplication run] + 646
9   com.apple.AppKit                0x00007fff9479c783 NSApplicationMain + 940
10  com.convo.swiftTest             0x000000010c3d5db2 main + 34
11  libdyld.dylib                   0x00007fff908fe5fd start + 1

Thread 1 Crashed:: Dispatch queue: com.apple.NSURLSession-work
0   libdispatch.dylib               0x00007fff9742d06f _os_object_retain_internal + 0
1   libdispatch.dylib               0x00007fff97435386 dispatch_group_notify_f + 98
2   com.apple.CFNetwork             0x00007fff92596857 -[__NSCFLocalSessionBridge invalidateSession:withQueue:completion:] + 612
3   com.apple.CFNetwork             0x00007fff9259fb13 -[__NSCFURLSession _onqueue_completeInvalidation:] + 152
4   com.apple.CFNetwork             0x00007fff9259fc47 __39-[__NSCFURLSession invalidateAndCancel]_block_invoke + 46
5   libdispatch.dylib               0x00007fff974301bb _dispatch_call_block_and_release + 12
6   libdispatch.dylib               0x00007fff9742d28d _dispatch_client_callout + 8
7   libdispatch.dylib               0x00007fff9742f673 _dispatch_queue_drain + 451
8   libdispatch.dylib               0x00007fff974309c1 _dispatch_queue_invoke + 110
9   libdispatch.dylib               0x00007fff9742ef87 _dispatch_root_queue_drain + 75
10  libdispatch.dylib               0x00007fff97430177 _dispatch_worker_thread2 + 40
11  libsystem_pthread.dylib         0x00007fff93ad2ef8 _pthread_wqthread + 314
12  libsystem_pthread.dylib         0x00007fff93ad5fb9 start_wqthread + 13

Thread 2:: Dispatch queue: com.apple.libdispatch-manager
0   libsystem_kernel.dylib          0x00007fff93ac4662 kevent64 + 10
1   libdispatch.dylib               0x00007fff9742f421 _dispatch_mgr_invoke + 239
2   libdispatch.dylib               0x00007fff9742f136 _dispatch_mgr_thread + 52

Thread 3:: Dispatch queue: printQueue
0   libsystem_platform.dylib        0x00007fff8ebd9d2b _platform_strcmp + 43
1   libicucore.A.dylib              0x00007fff8d602d29 0x7fff8d56c000 + 617769
2   libicucore.A.dylib              0x00007fff8d602e82 0x7fff8d56c000 + 618114
3   libicucore.A.dylib              0x00007fff8d6031f2 0x7fff8d56c000 + 618994
4   libicucore.A.dylib              0x00007fff8d56dd2e icu::Locale::init(char const*, signed char) + 268
5   libicucore.A.dylib              0x00007fff8d57f38a icu::Locale::createFromName(char const*) + 86
6   libicucore.A.dylib              0x00007fff8d57e8ba icu::Calendar::setWeekData(icu::Locale const&, char const*, UErrorCode&) + 234
7   libicucore.A.dylib              0x00007fff8d57d311 icu::GregorianCalendar::GregorianCalendar(icu::Locale const&, UErrorCode&) + 41
8   libicucore.A.dylib              0x00007fff8d57cda6 icu::Calendar::createInstance(icu::TimeZone*, icu::Locale const&, UErrorCode&) + 694
9   libicucore.A.dylib              0x00007fff8d57b21b ucal_open + 254
10  com.apple.CoreFoundation        0x00007fff92f9d0a6 __cficu_ucal_open + 54
11  com.apple.CoreFoundation        0x00007fff92f9cb3f __CFCalendarCreateUCalendar + 303
12  com.apple.CoreFoundation        0x00007fff92f9c08c CFCalendarCreateWithIdentifier + 588
13  com.apple.CoreFoundation        0x00007fff92fb1c40 __CFLogCString + 144
14  com.apple.CoreFoundation        0x00007fff92fb1b77 _CFLogvEx + 263
15  com.apple.Foundation            0x00007fff91bd339c NSLogv + 79
16  libswiftFoundation.dylib        0x000000010c8751e7 _TF10Foundation5NSLogFtSSGSaPSs11CVarArgType___T_ + 743
17  com.convo.swiftTest             0x000000010c4366ea _TFZFC9swiftTest12SocketLogger3logFMS0_FtSS6clientPS_15SocketLogClient_7altTypeGSqSS_4argsGSaPSs9AnyObject___T_U_FT_T_ + 1194
18  com.convo.swiftTest             0x000000010c43521a _TPA__TFZFC9swiftTest12SocketLogger3logFMS0_FtSS6clientPS_15SocketLogClient_7altTypeGSqSS_4argsGSaPSs9AnyObject___T_U_FT_T_ + 250
19  com.convo.swiftTest             0x000000010c3f9457 _TTRXFo__dT__XFdCb__dT__ + 39
20  libdispatch.dylib               0x00007fff974301bb _dispatch_call_block_and_release + 12
21  libdispatch.dylib               0x00007fff9742d28d _dispatch_client_callout + 8
22  libdispatch.dylib               0x00007fff9742f673 _dispatch_queue_drain + 451
23  libdispatch.dylib               0x00007fff974309c1 _dispatch_queue_invoke + 110
24  libdispatch.dylib               0x00007fff9742ef87 _dispatch_root_queue_drain + 75
25  libdispatch.dylib               0x00007fff97430177 _dispatch_worker_thread2 + 40
26  libsystem_pthread.dylib         0x00007fff93ad2ef8 _pthread_wqthread + 314
27  libsystem_pthread.dylib         0x00007fff93ad5fb9 start_wqthread + 13

Thread 4:
0   libsystem_kernel.dylib          0x00007fff93ac3e6a __workq_kernreturn + 10
1   libsystem_pthread.dylib         0x00007fff93ad2f08 _pthread_wqthread + 330
2   libsystem_pthread.dylib         0x00007fff93ad5fb9 start_wqthread + 13

Thread 5:: Dispatch queue: com.apple.ClassicConnectionSession
0   libobjc.A.dylib                 0x00007fff95873821 bool objc::DenseMapBase<objc::DenseMap<objc_object*, unsigned long, true, objc::DenseMapInfo<objc_object*> >, objc_object*, unsigned long, objc::DenseMapInfo<objc_object*>, true>::LookupBucketFor<objc_object*>(objc_object* const&, std::__1::pair<objc_object*, unsigned long> const*&) const + 93
1   libobjc.A.dylib                 0x00007fff9587361b objc::DenseMapBase<objc::DenseMap<objc_object*, unsigned long, true, objc::DenseMapInfo<objc_object*> >, objc_object*, unsigned long, objc::DenseMapInfo<objc_object*>, true>::find(objc_object* const&) + 35
2   libobjc.A.dylib                 0x00007fff9585d096 objc_clear_deallocating + 96
3   libobjc.A.dylib                 0x00007fff9585d020 objc_destructInstance + 126
4   libsystem_blocks.dylib          0x00007fff95a2f6f9 _Block_release + 205
5   libdispatch.dylib               0x00007fff9742d28d _dispatch_client_callout + 8
6   libdispatch.dylib               0x00007fff9742f673 _dispatch_queue_drain + 451
7   libdispatch.dylib               0x00007fff974309c1 _dispatch_queue_invoke + 110
8   libdispatch.dylib               0x00007fff9742ef87 _dispatch_root_queue_drain + 75
9   libdispatch.dylib               0x00007fff97430177 _dispatch_worker_thread2 + 40
10  libsystem_pthread.dylib         0x00007fff93ad2ef8 _pthread_wqthread + 314
11  libsystem_pthread.dylib         0x00007fff93ad5fb9 start_wqthread + 13

Thread 6:: com.apple.NSURLConnectionLoader
0   libsystem_kernel.dylib          0x00007fff93abfa1a mach_msg_trap + 10
1   libsystem_kernel.dylib          0x00007fff93abed18 mach_msg + 64
2   com.apple.CoreFoundation        0x00007fff92f7ff15 __CFRunLoopServiceMachPort + 181
3   com.apple.CoreFoundation        0x00007fff92f7f539 __CFRunLoopRun + 1161
4   com.apple.CoreFoundation        0x00007fff92f7ee75 CFRunLoopRunSpecific + 309
5   com.apple.Foundation            0x00007fff91bf5ff7 +[NSURLConnection(Loader) _resourceLoadLoop:] + 348
6   com.apple.Foundation            0x00007fff91bf5dfb __NSThread__main__ + 1318
7   libsystem_pthread.dylib         0x00007fff93ad1899 _pthread_body + 138
8   libsystem_pthread.dylib         0x00007fff93ad172a _pthread_start + 137
9   libsystem_pthread.dylib         0x00007fff93ad5fc9 thread_start + 13

Thread 7:: com.apple.CFSocket.private
0   libsystem_kernel.dylib          0x00007fff93ac39aa __select + 10
1   com.apple.CoreFoundation        0x00007fff92fcba03 __CFSocketManager + 867
2   libsystem_pthread.dylib         0x00007fff93ad1899 _pthread_body + 138
3   libsystem_pthread.dylib         0x00007fff93ad172a _pthread_start + 137
4   libsystem_pthread.dylib         0x00007fff93ad5fc9 thread_start + 13

Thread 8:
0   libsystem_kernel.dylib          0x00007fff93ac3e6a __workq_kernreturn + 10
1   libsystem_pthread.dylib         0x00007fff93ad2f08 _pthread_wqthread + 330
2   libsystem_pthread.dylib         0x00007fff93ad5fb9 start_wqthread + 13

Thread 9:
0   libsystem_kernel.dylib          0x00007fff93abfa1a mach_msg_trap + 10
1   libsystem_kernel.dylib          0x00007fff93abed18 mach_msg + 64
2   com.apple.CoreFoundation        0x00007fff92f7ff15 __CFRunLoopServiceMachPort + 181
3   com.apple.CoreFoundation        0x00007fff92f7f539 __CFRunLoopRun + 1161
4   com.apple.CoreFoundation        0x00007fff92f7ee75 CFRunLoopRunSpecific + 309
5   com.apple.AppKit                0x00007fff9495e05e _NSEventThread + 144
6   libsystem_pthread.dylib         0x00007fff93ad1899 _pthread_body + 138
7   libsystem_pthread.dylib         0x00007fff93ad172a _pthread_start + 137
8   libsystem_pthread.dylib         0x00007fff93ad5fc9 thread_start + 13

Thread 1 crashed with X86 Thread State (64-bit):
  rax: 0x0000600000266480  rbx: 0x0000600000266400  rcx: 0x00007fff974301af  rdx: 0x0000600000255390
  rdi: 0x0000000000000000  rsi: 0x0000000000000000  rbp: 0x000000010c9ecc00  rsp: 0x000000010c9ecbc8
   r8: 0x00000000000000ff   r9: 0xffff9fffffd9abff  r10: 0x00007fc26303e6a0  r11: 0x00005ffef3868760
  r12: 0x00007fff974301af  r13: 0x0000600000255390  r14: 0x00006000000bbf00  r15: 0x0000000000000000
  rip: 0x00007fff9742d06f  rfl: 0x0000000000010206  cr2: 0x0000000000000008

Logical CPU:     1
Error Code:      0x00000004
Trap Number:     14

App log:

7/3/15 9:48:35.091 AM swiftTest[3295]: SocketClient: Adding handler for event: connect 7/3/15 9:48:35.092 AM swiftTest[3295]: SocketClient: Adding handler for event: currentAmount 7/3/15 9:48:35.092 AM swiftTest[3295]: SocketClient: Adding handler for event: error 7/3/15 9:48:35.092 AM swiftTest[3295]: SocketClient: Adding handler for event: disconnect 7/3/15 9:48:35.092 AM swiftTest[3295]: SocketClient: Adding handler for event: reconnect 7/3/15 9:48:35.093 AM swiftTest[3295]: SocketClient: Adding handler for event: reconnectAttempt 7/3/15 9:48:35.093 AM swiftTest[3295]: SocketClient: Adding handler for event: message 7/3/15 9:48:35.093 AM swiftTest[3295]: SocketClient: Adding handler for event: connection 7/3/15 9:48:35.094 AM swiftTest[3295]: SocketClient: Adding handler for event: event 7/3/15 9:48:35.094 AM swiftTest[3295]: SocketClient: Adding engine 7/3/15 9:48:35.094 AM swiftTest[3295]: SocketEngine: Starting engine 7/3/15 9:48:35.094 AM swiftTest[3295]: SocketEngine: Handshaking 7/3/15 9:48:35.095 AM swiftTest[3295]: SocketEngine: Doing polling request 7/3/15 9:48:35.303 AM swiftTest[3295]: SocketEngine: Got polling response 7/3/15 9:48:35.311 AM swiftTest[3295]: ERROR SocketEngine: Parsing error: <!DOCTYPE html>

Error 404 (Not Found)!!1

404. That’s an error.

The requested URL /socket.io/ was not found on this server. That’s all we know. 7/3/15 9:48:35.312 AM swiftTest[3295]: ERROR SocketClient: Error parsing XHR message 7/3/15 9:48:35.312 AM swiftTest[3295]: SocketClient: Handling event: error with data: ( "Error parsing XHR message" ) 7/3/15 9:48:35.313 AM swiftTest[3295]: SocketClient: Handling event: reconnect with data: ( "Error parsing XHR message" ) 7/3/15 9:48:35.313 AM swiftTest[3295]: SocketClient: Starting reconnect 7/3/15 9:48:35.313 AM swiftTest[3295]: SocketClient: Trying to reconnect 7/3/15 9:48:35.314 AM swiftTest[3295]: SocketClient: Handling event: reconnectAttempt with data: ( "-1" ) 7/3/15 9:48:35.314 AM swiftTest[3295]: SocketClient: Adding engine 7/3/15 9:48:35.314 AM swiftTest[3295]: SocketEngine: Starting engine 7/3/15 9:48:35.315 AM swiftTest[3295]: SocketEngine: Handshaking 7/3/15 9:48:35.315 AM swiftTest[3295]: SocketEngine: Doing polling request 7/3/15 9:48:35.315 AM swiftTest[3295]: SocketEngine: Engine is being deinit 7/3/15 9:48:35.323 AM swiftTest[3295]: socket error 7/3/15 9:48:35.324 AM swiftTest[3295]: socket reconnect 7/3/15 9:48:35.324 AM swiftTest[3295]: socket reconnectAttempt 7/3/15 9:48:35.491 AM swiftTest[3295]: SocketEngine: Got polling response 7/3/15 9:48:35.496 AM swiftTest[3295]: socket error 7/3/15 9:48:35.497 AM swiftTest[3295]: ERROR SocketEngine: Parsing error: Error 404 (Not Found)!!1

404. That’s an error.

The requested URL /socket.io/ was not found on this server. That’s all we know. 7/3/15 9:48:35.497 AM swiftTest[3295]: ERROR SocketClient: Error parsing XHR message 7/3/15 9:48:35.498 AM swiftTest[3295]: SocketClient: Handling event: error with data: ( "Error parsing XHR message" ) 7/3/15 9:48:40.346 AM com.apple.launchd.peruser.501[178]: (com.convo.swiftTest.75008[3295]) Job appears to have crashed: Segmentation fault: 11 7/3/15 9:48:40.441 AM ReportCrash[3298]: Saved crash report for swiftTest[3295] version 1.0 (1) to /Users/xxx/Library/Logs/DiagnosticReports/swiftTest_2015-07-03-094840_xxx-Mac-mini.crash ``` ```

nuclearace commented 9 years ago

I'm having trouble reproducing with your example app

EduardoAlberti commented 9 years ago

The issue is intermittent, you have to call 'closeWithFast' in the same time when the socket is reconnecting. Also, don't use the 'start' button, instead, you have to restart the app in every try. Remember, the issue is presented on Mavericks only. Hope this helps you.

nuclearace commented 9 years ago

Hm, if it only happens on mavericks I would say it's a bug in NSURLSession in mavericks