| Summary: | Safari tab freeze and gpu process crash when calling canvas function drawimage/getimagedata/setimagedata from high resolution getUserMedia stream with several background tabs | ||||||||
|---|---|---|---|---|---|---|---|---|---|
| Product: | WebKit | Reporter: | Shawn Lee <shawnlee> | ||||||
| Component: | Canvas | Assignee: | youenn fablet <youennf> | ||||||
| Status: | RESOLVED FIXED | ||||||||
| Severity: | Normal | CC: | dino, hagaib, jer.noble, kkinnunen, sabouhallawa, shawnlee, simon.fraser, webkit-bug-importer, youennf | ||||||
| Priority: | P2 | Keywords: | InRadar | ||||||
| Version: | Safari 16 | ||||||||
| Hardware: | Unspecified | ||||||||
| OS: | Unspecified | ||||||||
| See Also: | https://bugs.webkit.org/show_bug.cgi?id=258977 | ||||||||
| Attachments: |
|
||||||||
|
Description
Shawn Lee
2023-05-05 06:57:46 PDT
Created attachment 466270 [details]
Screen cast
screencast
Did this happen prior to iOS 16.4? Some(In reply to Simon Fraser (smfr) from comment #3) > Did this happen prior to iOS 16.4? The demo is not tested before 16.4 as I can not downgrade the phone. For our website that depends on this operation, it do happens sometimes before but not as often as 16.4 It becomes much easier to trigger the issue after I update he device to 16.4, When there several tabs already open in safari. https://websdk.demos.scandit.com/ A real world application where this issue occurred. Select 4k camera on the top menu. It will freeze if you have many tabs in background. The issue has become more severe in iOS 17 beta, rendering our website completely unusable. Thank you for the report. I can reproduce. It appears GPU process fails to attribute the images and runs out of memory https://lcg3ks.csb.app/ Looks like there is memory leak when drawing getUserMedia video from to canvas or create bitmap from getUserMedia if you do not close the tab. I have create another demo. First open instruments to monitor the memory usage of com.apple.webkit.gpu. Then click "Start drawImage from camera", it will start play video and call drawImage. Click stop to stop video and remove canvas and video frame the page. Click replace location to ensure there are no page caches. Run console.takeHeapSnapshot in inspector to trigger gc. observer that the memory usage of com.apple.webkit.gpu. is increased to 100mb. If you close the tab, the memory is freed. If you have more tabs, the memory get accumulated, and eventually the system kills the gpu process and safari can not recovery for the foreground tab. Also notice that he leaks do not happens if the video is comes from file instead of camera. createImageBitmap also trigger the leaks. Just tested the leak can be reproduced on desktop safari 16.4 using continuity camera. Please test iOS 17 beta, where this issue should be resolved. It was fixed via bug 258977. *** This bug has been marked as a duplicate of bug 258977 *** I have test with ios 17 beta 7 and latest safari Technology preview 177. The leaks is still exist. I think it is not a duplicate of bug 258977. It seems that the bug 258977 only happens when switch player engine. While my demo only play video from getUserMedia. I have also try to update the demo to not to set url to empty when stop the video. The leak still exists https://3t65yt.csb.app/ Aloo, when testing with my demo, you can create qrcodes with some query parameters. Like https://3t65yt.csb.app/?1 https://3t65yt.csb.app/?2 https://3t65yt.csb.app/?3 https://3t65yt.csb.app/?4 And open the link from camera app. That can ensure new content process being created for each tab. From my observation, the leak happens once for each content process. Also notice that the leak happens only when drawImage is called. Without drawImage the memory of gpu process shrink back to original after video is stopped. Created attachment 467443 [details]
CVPixelBufferPool in memory graph after page is navigated away
The CVPixelBufferPool is retained even after the page is navigated away.
The CVPixelBufferPool is retained by cached reference of PixelBufferConformerCV, if I set it to nullptr after use, the memory usage of com.apple.webkit.gpu grows much slower. https://github.com/WebKit/WebKit/blob/2a288d2a3ca713875fe7474e8c70f3e304edbd74/Source/WebKit/GPUProcess/media/RemoteVideoFrameObjectHeap.cpp#L164-L170 Pull request: https://github.com/apple/WebKit/pull/773 Pull request: https://github.com/WebKit/WebKit/pull/17808 Committed 268444@main (9f4b18808c83): <https://commits.webkit.org/268444@main> Reviewed commits have been landed. Closing PR #17808 and removing active labels. |