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

Fix App does not automatically reconnect to HU after changing language #1590

Merged
merged 2 commits into from Apr 9, 2020
Merged

Conversation

zhouxin627
Copy link
Contributor

@zhouxin627 zhouxin627 commented Mar 17, 2020

Fixes #1532

This PR is ready for review.

Risk

This PR makes no API changes.

Testing Plan

Covered by Unit tests.

Summary

Reason

  1. There are two threads (ioStreamThread and lifecycleThread) have Proxy object
  2. After HU changing language, Proxy's UnregisterApp is invoked
  3. Then lifecycleThread's stopManager is invoked
  4. set Proxy = nil and then Proxy's reference count will reduce to 0
  5. when Proxy's reference count reaches 0,Proxy's dealloc method will be invoked

Normal case:
5.1.1 Proxy's dealloc is invoked in the lifecycleThread
5.1.2 set ioStreamThread's cancel flag true
5.1.3 ioStreamThread exit
5.1.4 close Session
5.1.5 ioStreamThread = nil
5.1.6 create new session successfully
image

Abnormal case:
5.2.1 Proxy's dealloc is invoked in the ioStreamThread
5.2.2 set ioStreamThread's cancel falg true
5.2.3 ioStreamThread = nil
5.2.4 ioStreamThread exit faild
5.2.5 create new session failed
image

Solution
Avoid ioStreamThread do expensive operations, so move the methods in the dealloc to the new method of disconnectSession, before set Proxy = nil, execute disconnectSession.

  1. There are two threads (ioStreamThread and lifecycleThread) have Proxy object
  2. After HU changing language, Proxy's UnregisterApp is invoked
  3. Then lifecycleThread's stopManager is invoked
  4. Invoke Proxy's disconnectSession method in the lifecycleThread
  5. Set ioStreamThread's cancel flag true
  6. ioStreamThread exit
  7. Close Session
  8. ioStreamThread = nil
  9. Set Proxy = nil and then Proxy's reference count will reduce to 0
  10. When Proxy's reference count reaches 0,Proxy's dealloc method will be invoked
  11. Create new session successful
    image

CLA

@joeljfischer joeljfischer added bug A defect in the library manager-lifecycle Relating to the manager layer - lifecycle manager labels Mar 18, 2020
@joeljfischer joeljfischer changed the title Bugfix/issue 1532 App does not automatically reconnect to HU after changing language Fix App does not automatically reconnect to HU after changing language Mar 18, 2020
@joeljfischer
Copy link
Contributor

@zhouxin627 Thanks for the PR. Have you determined if this PR or something similar is needed on Java_Suite?

@zhouxin627
Copy link
Contributor Author

Hi @joeljfischer, I think there is no need to modify Java_Suite because it can work well.

@joeljfischer
Copy link
Contributor

A few questions:

There are two threads (ioStreamThread and lifecycleThread) have Proxy object

This doesn't seem to be true, only the lifecycle manager has a proxy object.

Proxy's dealloc is invoked in the ioStreamThread

Where does this happen. proxy = nil only occurs in SDLLifecycleManager.sdl_stopManager: that I can find (7 on your "abnormal case" chart).

@zhouxin627
Copy link
Contributor Author

Hi @joeljfischer

This doesn't seem to be true, only the lifecycle manager has a proxy object.

When the head unit sends data to the phone, the session will transfer data to Proxy, and this
transferring is handled in ioStreamThread.

Where does this happen. proxy = nil only occurs in SDLLifecycleManager.sdl_stopManager: that I can find (7 on your "abnormal case" chart).

The function(proxy = nil) is indeed handled in sdl_stopManager, but the iOS project manages resources with ARC. When ARC works, the time of dealloc and execution thread is based on the release function called by the system, which is used in the case of the count is zero.

The proxy object is owed by ioStreamThread and LlifecycleThread, so the last time releasing will probably happen in the ioStreamThread, and this will cause dealloc to execute in ioStreamThread.

@joeljfischer joeljfischer self-requested a review March 25, 2020 15:54
@joeljfischer joeljfischer added this to In progress in v6.6.0 via automation Mar 25, 2020
SmartDeviceLink/SDLMutableDataQueue.m Outdated Show resolved Hide resolved
SmartDeviceLink/SDLProxy.h Outdated Show resolved Hide resolved
SmartDeviceLink/SDLProxy.m Outdated Show resolved Hide resolved
v6.6.0 automation moved this from In progress to Waiting for Review Mar 25, 2020
@zhouxin627 zhouxin627 closed this Mar 26, 2020
v6.6.0 automation moved this from Waiting for Review to Done Mar 26, 2020
@joeljfischer
Copy link
Contributor

Hello @zhouxin627, are you considering this bug no longer as needing a fix? Are you planning on re-opening this PR?

@zhouxin627
Copy link
Contributor Author

Hi @joeljfischer, yes, I want to re-opening this PR. It was closed automatically when I revert NSInteger const MAXDATACOUNT = 200;. Now, It is showing No commits yet and Pushing new commits will allow the pull request to be re-opened.. I'm investigating how to deal with it.

@zhouxin627 zhouxin627 reopened this Apr 2, 2020
v6.6.0 automation moved this from Done to In progress Apr 2, 2020
@theresalech
Copy link
Contributor

@zhouxin627 can you please confirm if this PR is now ready for Livio's review?

@zhouxin627
Copy link
Contributor Author

@theresalech Hi, this PR is now ready for review.

v6.6.0 automation moved this from In progress to Waiting for Review Apr 8, 2020
Copy link
Contributor

@joeljfischer joeljfischer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one small comment for you to alter!

SmartDeviceLink/SDLProxy.h Outdated Show resolved Hide resolved
Co-Authored-By: Joel Fischer <joeljfischer@gmail.com>
v6.6.0 automation moved this from Waiting for Review to Reviewer approved Apr 9, 2020
@joeljfischer joeljfischer merged commit 72bd096 into smartdevicelink:develop Apr 9, 2020
v6.6.0 automation moved this from Reviewer approved to Done Apr 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A defect in the library manager-lifecycle Relating to the manager layer - lifecycle manager
Projects
No open projects
v6.6.0
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

3 participants