Summary: | Safari crashes after ~2028 OfflineAudioContext objects are created (they never get garbage collected, consuming a thread each) | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Product: | WebKit | Reporter: | schngrg <schngrg> | ||||||||||
Component: | Web Audio | Assignee: | youenn fablet <youennf> | ||||||||||
Status: | RESOLVED FIXED | ||||||||||||
Severity: | Normal | CC: | commit-queue, eric.carlson, ews-watchlist, jer.noble, rniwa, schngrg, webkit-bug-importer, youennf | ||||||||||
Priority: | P2 | Keywords: | InRadar | ||||||||||
Version: | Safari 12 | ||||||||||||
Hardware: | All | ||||||||||||
OS: | All | ||||||||||||
Attachments: |
|
Description
schngrg
2019-06-18 08:14:31 PDT
Above for loop is only test code to reproduce the problem quickly. The actual application was receiving new audio data every 100ms, loading it in a AudioBuffer to use with AudioBufferSourceNode.start() and calling OfflineAudioContext.startRendering(). The oncomplete callback is successfully called. But nothing gets garbage collected (all the buffers etc stay), making it look like a memory leak. But as a hack, setting oncomplete = null after oncomplete is called causes garbage collection of everything except OfflineAudioContext objects. Very little memory is consumed by the OfflineAudioContext objects, < 40KB total. But OfflineAudioContext objects seem to be holding on to the threads causing a crash as soon as around 2020 to 2035 objects are created. Trying to call AudioBufferSourceNode.stop(), AudioBufferSourceNode.disconnect(), setting all web-audio objects to null in or after oncomplete, etc doesn't help. I cannot reproduce the crash on latest MacOS. Thread increase is probably due to AsyncAudioDecoder. It does not seem great to create a decoding thread per AudioContext, since it might never be used in practice. At least this should be lazily initialized. Agreed OfflineAudioContext should be easily GCable, at least once it has finished its task. I can reproduce the crash using Safari Technology Preview 85 on macOS. Using the for loop in my first post that just creates 3000 OfflineAudioContexts. Note that same crash occurs even with the normal AudioContext, but it might be less of a problem with AudioContext as that is very unlikely to get created so many times. GC is probably blocked by the setPendingActivity call in AudioContext::constructCommon in C++ code? (I am very new to webkit code, just built it for first time few days ago to try and figure out this crash). > GC is probably blocked by the setPendingActivity call in
> AudioContext::constructCommon in C++ code? (I am very new to webkit code,
> just built it for first time few days ago to try and figure out this crash).
Welcome to WebKit!
And yep, that is probably the issue.
Created attachment 372487 [details]
Patch
(In reply to youenn fablet from comment #6) > Created attachment 372487 [details] > Patch This patch delays setting pending activity of an OfflineAudioContext until startsRendering is called. I think this is ok but might need some additional study. In case finishedRendering exits in case of renderedBuffer is null, there is a chance the OfflineAudioContext gets GCed while a state change event might be enqueued. This seems ok to me as renderedBuffer is not supposed to be null for offline audio contexts. Thanks :-) Comment on attachment 372487 [details] Patch Attachment 372487 [details] did not pass mac-ews (mac): Output: https://webkit-queues.webkit.org/results/12523687 New failing tests: webaudio/mediaelementaudiosourcenode-gc.html webaudio/offlineaudiocontext-gc.html Created attachment 372492 [details]
Archive of layout-test-results from ews103 for mac-highsierra
The attached test failures were seen while running run-webkit-tests on the mac-ews.
Bot: ews103 Port: mac-highsierra Platform: Mac OS X 10.13.6
Created attachment 372493 [details]
Patch
Created attachment 372494 [details]
Patch
Comment on attachment 372494 [details] Patch Clearing flags on attachment: 372494 Committed r246685: <https://trac.webkit.org/changeset/246685> All reviewed patches have been landed. Closing bug. |