smartdevicelink / sdl_ios

Get your app connected to the 🚙, make your users feel like a 🌟
www.smartdevicelink.com
BSD 3-Clause "New" or "Revised" License
169 stars 105 forks source link

Crash in iOS Proxy on Transport Dealloc #672

Closed davidswi closed 2 years ago

davidswi commented 7 years ago

Bug Report

In automated USB connect/disconnect testing with 30s cycle time, there appears to be a timing issue where the SDLIAPTransport dealloc method is called with an open control session and without disconnect being called. This will cause the open output stream to call the dealloc'ed delegate, resulting in a crash.

Reproduction Steps
  1. Pair iOS device to head unit and launch SDL app
  2. Connect iOS device to programmable USB hub
  3. Start automated USB cycle testing
Expected Behavior

No crashes, app resumes after every reconnection

Observed Behavior

App crashes with trace similar to:

Thread 0 name:  Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0   libobjc.A.dylib                 0x0000000195193bd0 objc_msgSend + 16
1   ExternalAccessory               0x00000001842b31c4 -[EAOutputStream _streamEventTrigger] + 212
2   CoreFoundation                  0x000000018346bf88 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 20
3   CoreFoundation                  0x000000018346b2e4 __CFRunLoopDoSources0 + 444
4   CoreFoundation                  0x00000001834692dc __CFRunLoopRun + 708
5   CoreFoundation                  0x0000000183394f70 CFRunLoopRunSpecific + 392
6   GraphicsServices                0x000000018cdef6f8 GSEventRunModal + 164
7   UIKit                           0x0000000187f96d90 UIApplicationMain + 1484
8   CompanionApp-P3-Lexus           0x0000000100092610 main (main.m:19)
9   libdyld.dylib                   0x000000019582aa04 start + 0
OS & Version Information
Test Case, Sample Code, and / or Example App

This should be reproducible with the SDL example app.

NicoleYarroch commented 7 years ago

I have been unable to reproduce this bug using the SDL Example app. While testing I did find that the app crashes if the USB cord is disconnected right after the app icon is set up but before the HMI is setup. I have created a WIP Pull Request #752 to fix said bug.

It would be helpful to know where in the lifecycle the bug is happening. Is it when the USB cord is disconnected while accessory setup is occurring or after it has been connected/disconnected several times, or some other point in the lifecycle?

NicoleYarroch commented 7 years ago

I just had this error occur after pulling the USB cord multiple times. It looks like there is no error handling occurring in the SDLIAPSession's stop method when the ioStreamThread fails to cancel. The ioStreamThread then gets set to nil even though the NSStream is still open. This causes the app to crash.

I've added logs for the crashed app session for the Streaming Video Example app. NSStream Crash 2017-09-25-09:19:10-smartdevicelink.log

davidswi commented 7 years ago

I've reviewed the changes to this PR and it seems fine to me. I'd like to know why the ioStreamThread is not canceling within the dispatch semaphore timeout period. I think that needs to be investigated and resolved if possible.

NicoleYarroch commented 6 years ago

Issue has reported again on v. 5.2.

I just had this error occur after pulling the USB cord multiple times. It looks like there is no error handling occurring in the SDLIAPSession's stop method when the ioStreamThread fails to cancel. The ioStreamThread then gets set to nil even though the NSStream is still open. This causes the app to crash.

NicoleYarroch commented 6 years ago

Reproducible steps from the iOS Slack Channel from Vlad

  1. Start the app and connect to the head unit.
  2. Move app to the background, and return it back to foreground.
  3. Select app on the head unit (start video streaming).
  4. Repeat it up to 15 times.
NicoleYarroch commented 6 years ago

May be related to issue #1002

joeljfischer commented 5 years ago

@NicoleYarroch was this fixed with #1011