Tencent / Tencent/libpag

PAGImageView 加载网络Pag资源在弱网或超时场景内部重试导致的ANR

Open
#2,590 2 comments 0 reactions 1 assignee View on GitHub

@kevingpqi123 is already working on this.

Since Nov 18, 2024.

Dominant language
HTML
Stars
5.8k
Forks
531
Avg merge
8d 55m
Merged PRs (30d)
17

Description

【版本信息】

4.3.33
master也是同样代码,应该也有此问题

【平台信息】

Android 原生

【预期的表现】

进入页面调用setPathAync 加载网络PAG资源,弱网环境下快速退出页面或者removePagView 无ANR问题出现

【实际的情况】

进入页面调用setPathAync 加载网络PAG资源,弱网环境下快速退出页面或者removePagView 有概率导致导致ANR,问题发生在
PagImageView->onDetachedFromWindow->decoderInfo.reset()
image

原因分析

  1. decoderInfo.reset() 为同步方法
image
  1. 调用setPathAync 如果弱网环境或请求失败的场景下会回调到 onAnimationUpdate->flush()
image
  1. flush方法此时会调用initDecoderInfo,initDecoderInfo使用了deocderInfo的对象锁,并且会重新从网络加载Pag资源导致deocderInfo对象锁长期持有
image image
  1. 如果此时退出Activity或者removeView等操作导致PAGImageView的onDetachFromWindow回调,调用到第1步的 decoderInfo.reset(),此时decoderInfo被作为对象锁被initDecoderInfo所在线程持有,主线程的decoderInfo.reset()等待子线程的decoderinfo对象锁释放,此时容易ANR

【Demo及附件】

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.