Skip to content

Fix missing console.logs on Android when CLI is used as library #3198

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

Merged
merged 1 commit into from
Nov 7, 2017

Conversation

rosen-vladimirov
Copy link
Contributor

@rosen-vladimirov rosen-vladimirov commented Nov 6, 2017

In case CLI is used as a library, the device logs are no longer captured after application is restarted. The problem is the newly added logic for Android devices that stops the logcat process when CLI calls stopApplication and starts it when startApplication is called.
However, in startApplication there's a check if $options.justlaunch is false - only then the device log operation is started again.
When CLI is used as a library, we have hardcoded the justlaunch option to true in order to prevent duplicate logs for iOS devices. So the solution to resolve Android logs issues is to remove the setting of justlaunch option.
However, this caused the duplicate logs issue for iOS devices. Investigating it further, it turned out to be a memory leak when iOS device is detached. It's fixed in the submodule:

Fix leaking handlers for iOS device logs

In case iOS Device is detached, the IOSDevice instance is kept alive. The reason is the handler for device logs, that IOSDevice passes to iOSDeviceOperations.
As iOSDeviceOperations is still alive, the IOSDevice instance is also alive. Reattaching the same device will cause duplicate logs. Detaching and attaching it again will lead to additional logs.

In order to fix the issue, convert iOSDeviceOpertations to event emitter and emit event when there's data for logging. Each IOSDevice will add handler for the event and will do its logic.
In case device is detached (i.e. DeviceLost event is fired in DevicesService), call a newly added method to the specific IDevice instance. It's purpose is to clean the used resource.
For iOS device, this method will remove the handler for devceLogData event of iOSDeviceOperations.

@dtopuzov
Copy link
Contributor

dtopuzov commented Nov 6, 2017

run ci

Copy link
Contributor

@Mitko-Kerezov Mitko-Kerezov left a comment

Choose a reason for hiding this comment

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

LGTM

In case CLI is used as a library, the device logs are no longer captured after application is restarted. The problem is the newly added logic for Android devices that stops the logcat process when CLI calls `stopApplication` and starts it when `startApplication` is called.
However, in `startApplication` there's a check if `$options.justlaunch` is false - only then the device log operation is started again.
When CLI is used as a library, we have hardcoded the `justlaunch` option to true in order to prevent duplicate logs for iOS devices. So the solution to resolve Android logs issues is to remove the setting of justlaunch option.
However, this caused the duplicate logs issue for iOS devices. Investigating it further, it turned out to be a memory leak when iOS device is detached. It's fixed in the submodule:

In case iOS Device is detached, the `IOSDevice` instance is kept alive. The reason is the handler for device logs, that `IOSDevice` passes to `iOSDeviceOperations`.
As `iOSDeviceOperations` is still alive, the `IOSDevice` instance is also alive. Reattaching the same device will cause duplicate logs. Detaching and attaching it again will lead to additional logs.

In order to fix the issue, convert `iOSDeviceOpertations` to event emitter and emit event when there's data for logging. Each `IOSDevice` will add handler for the event and will do its logic.
In case device is detached (i.e. `DeviceLost` event is fired in `DevicesService`), call a newly added method to the specific `IDevice` instance. It's purpose is to clean the used resource.
For iOS device, this method will remove the handler for `devceLogData` event of `iOSDeviceOperations`.
@rosen-vladimirov rosen-vladimirov force-pushed the vladimirov/fix-sidekick-justlaunch branch from 5e10add to 980637e Compare November 7, 2017 09:46
@rosen-vladimirov rosen-vladimirov merged commit 48d2926 into master Nov 7, 2017
@rosen-vladimirov rosen-vladimirov deleted the vladimirov/fix-sidekick-justlaunch branch November 7, 2017 10:36
rosen-vladimirov added a commit that referenced this pull request Nov 13, 2017
In case CLI is used as a library, the device logs are no longer captured after application is restarted. The problem is the newly added logic for Android devices that stops the logcat process when CLI calls `stopApplication` and starts it when `startApplication` is called.
However, in `startApplication` there's a check if `$options.justlaunch` is false - only then the device log operation is started again.
When CLI is used as a library, we have hardcoded the `justlaunch` option to true in order to prevent duplicate logs for iOS devices. So the solution to resolve Android logs issues is to remove the setting of justlaunch option.
However, this caused the duplicate logs issue for iOS devices. Investigating it further, it turned out to be a memory leak when iOS device is detached. It's fixed in the submodule:

In case iOS Device is detached, the `IOSDevice` instance is kept alive. The reason is the handler for device logs, that `IOSDevice` passes to `iOSDeviceOperations`.
As `iOSDeviceOperations` is still alive, the `IOSDevice` instance is also alive. Reattaching the same device will cause duplicate logs. Detaching and attaching it again will lead to additional logs.

In order to fix the issue, convert `iOSDeviceOpertations` to event emitter and emit event when there's data for logging. Each `IOSDevice` will add handler for the event and will do its logic.
In case device is detached (i.e. `DeviceLost` event is fired in `DevicesService`), call a newly added method to the specific `IDevice` instance. It's purpose is to clean the used resource.
For iOS device, this method will remove the handler for `devceLogData` event of `iOSDeviceOperations`.
@bigradish
Copy link

bigradish commented Nov 19, 2017

@rosen-vladimirov , console.log also does not work on android when CLI is NOT used as a library. You can refer to issue #3118 . Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants