-
Notifications
You must be signed in to change notification settings - Fork 1.7k
PDFPlugin hangs in deallocation when data load contends with waiting for thread completion #25448
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
Conversation
EWS run on previous version of this PR (hash 93c2661)
|
93c2661
to
6ac3495
Compare
EWS run on previous version of this PR (hash 6ac3495)
|
6ac3495
to
f9f5332
Compare
EWS run on previous version of this PR (hash f9f5332)
|
for (size_t i = 0; i < count; ++i) { | ||
protectedLoader->getResourceBytesAtPosition(ranges[i].length, ranges[i].location, [i, &dataResults, &dataSemaphore](const uint8_t* bytes, size_t bytesCount) { | ||
protectedLoader->getResourceBytesAtPosition(ranges[i].length, ranges[i].location, [i, &dataResults, callbackAggregator](const uint8_t* bytes, size_t bytesCount) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 not sure how callbackAggregator
works but will it get called for each loop? if that is the case, we just wait
one time, and it is a BinarySemaphore. (i was quite hesitate if we should also address for this callback)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
callbackAggregator calls its lambda on destruction. Since I capture it by value in each lambda inside the loop, we will only signal the semaphore ONCE, when all getResourceBytesAtPosition()
calls have completed. As a result, we only need a single semaphore / a single wait()
. This simplifies the code.
506a859
to
5ffcd92
Compare
EWS run on previous version of this PR (hash 506a859)
|
EWS run on current version of this PR (hash 5ffcd92) |
…for thread completion https://bugs.webkit.org/show_bug.cgi?id=246454 rdar://101147811 Reviewed by Tim Horton. When `PDFPlugin::teardown()` would get called (on the main thread), it would wait for the PDF thread to complete. However, if loading is still going on, the PDF thread might be blocked on `dataSemaphore.wait()` in PDFIncrementalLoader::dataProviderGetBytesAtPosition(). The `dataSemaphore` is supposed to get signaled on a task dispatched to the main thread but this task won't run if the main thread is blocked on waiting for the thread to exit. To address the issue, PDFIncrementalLoader::clear() now signals the pending dataSemaphores before waiting for the thread to exit and sets a flag indicating we want the thread to exit. This flag is then checked on the PDF thread to make sure we don't queue additional work / semaphores. * LayoutTests/compositing/plugins/pdf/pdf-plugin-hang-during-destruction-expected.txt: Added. * LayoutTests/compositing/plugins/pdf/pdf-plugin-hang-during-destruction.html: Added. I took the test from Erica Li's earlier PR that got reverted. * Source/WebKit/WebProcess/Plugins/PDF/PDFIncrementalLoader.h: (WebKit::PDFIncrementalLoader::SemaphoreWrapper::create): (WebKit::PDFIncrementalLoader::SemaphoreWrapper::wait): (WebKit::PDFIncrementalLoader::SemaphoreWrapper::signal): (WebKit::PDFIncrementalLoader::WTF_GUARDED_BY_LOCK): * Source/WebKit/WebProcess/Plugins/PDF/PDFIncrementalLoader.mm: (WebKit::PDFIncrementalLoader::clear): (WebKit::PDFIncrementalLoader::dataProviderGetBytesAtPosition): (WebKit::PDFIncrementalLoader::dataProviderGetByteRanges): (WebKit::PDFIncrementalLoader::threadEntry): Canonical link: https://commits.webkit.org/275707@main
5ffcd92
to
e604d7c
Compare
Committed 275707@main (e604d7c): https://commits.webkit.org/275707@main Reviewed commits have been landed. Closing PR #25448 and removing active labels. |
e604d7c
5ffcd92