Skip to content

Run getGlobalVisibleRect on the main thread instead of a background thread#736

Merged
jsligh merged 4 commits intomasterfrom
735-crash-for-mraid-ads
Jan 19, 2024
Merged

Run getGlobalVisibleRect on the main thread instead of a background thread#736
jsligh merged 4 commits intomasterfrom
735-crash-for-mraid-ads

Conversation

@jsligh
Copy link
Copy Markdown
Collaborator

@jsligh jsligh commented Jan 17, 2024

Closes #735

@jsligh jsligh self-assigned this Jan 17, 2024
@jsligh jsligh linked an issue Jan 17, 2024 that may be closed by this pull request
@jsligh jsligh marked this pull request as ready for review January 17, 2024 21:32
adBaseView.getGlobalVisibleRect(rect);

Handler mainHandler = new Handler(Looper.getMainLooper());
mainHandler.post(() -> adBaseView.getGlobalVisibleRect(rect));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The quick search shows that there are more than 20 usages of the adBaseView object in the BaseJSInterface class.

image

I'm afraid any of them can lead to a similar crash.

I'd suggest really, hard to reproduce the current crash first, then fix it, then try to reproduce with other usages of the adBaseView before the release. It will help to understand the curcomstanses and prevent other crashes, potentially in the same ads.

If we can't reproduce it, of course, we need to release the fix based on the assumptions, but it is better to cover as much potential cases as possible. Otherwice we will get the same crash statistic but with another method, for example: adBaseView.getGlobalVisibleRect(rect)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I have already looked through the usages, most are checks if null or are already called on the main/ui thread. I have not been able to reproduce though and you are correct that we need to try to reproduce first.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It looks like the Handler runs the task asynchronously. However, we need the data synchronously to process it in the next step.

image

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Here is the behaviour before changes

image

@jsligh jsligh marked this pull request as draft January 17, 2024 22:01
Copy link
Copy Markdown
Contributor

@YuriyVelichkoPI YuriyVelichkoPI left a comment

Choose a reason for hiding this comment

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

Ok, it should fix the current crash. But I'm not sure about all other possible cases.

Ideally, since we've faced such an issue, we should wrap a managed WebView in some background-thread-safe-invocation wrapper. To make sure that all clients of the JS bridge (ad code and SDK code) can use in safely. It could be done in the scope of the separate tech debt ticket.

adBaseView.getGlobalVisibleRect(rect);

Handler mainHandler = new Handler(Looper.getMainLooper());
mainHandler.post(() -> adBaseView.getGlobalVisibleRect(rect));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Here is the behaviour before changes

image

@YuriyVelichkoPI
Copy link
Copy Markdown
Contributor

I think we should release this hotfix as soon as possible, since it leads to multiple crashes right now.

@jsligh
Copy link
Copy Markdown
Collaborator Author

jsligh commented Jan 19, 2024

I think we should release this hotfix as soon as possible, since it leads to multiple crashes right now.

I will be merging this and the other PR's and putting out a release today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Crash for MRAID ads

2 participants