Skip to content
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

Internal concurrency limit is sometimes saturated by trimToByteSize: calls (while another trim is in progress). #135

Closed
appleguy opened this issue Oct 28, 2016 · 0 comments · Fixed by #141
Assignees
Milestone

Comments

@appleguy
Copy link
Contributor

appleguy commented Oct 28, 2016

This set of stacks shows the issue. Fortunately this should be easy to fix: before we schedule any trimToByteSize: call, we should check a global BOOL to see if another trim is either scheduled, or currently running.

This would need a global lock, but it should be rarely contended. We could later use that global lock to also protect access to the trash, allowing us to delete the trash directory as one unit and then recreate the trash directory before any other items are moved to the trash.

  thread #49: tid = 0x1054b5, 0x21f5e998 libsystem_kernel.dylib`__psynch_cvwait + 24, queue = 'PINOperationQueue Serial Queue'
    frame #0: 0x21f5e998 libsystem_kernel.dylib`__psynch_cvwait + 24
    frame #3: 0x22a35a06 Foundation`-[NSCondition waitUntilDate:] + 286
    frame #4: 0x22a33030 Foundation`-[NSConditionLock lockWhenCondition:beforeDate:] + 208
    frame #5: 0x0122800c Pinterest Enterprise`-[PINDiskCache lock](self=0x178893b0, _cmd="lock") + 60 at PINDiskCache.m:1243
    frame #6: 0x0121f804 Pinterest Enterprise`-[PINDiskCache trimDiskToSizeByDate:](self=0x178893b0, _cmd="trimDiskToSizeByDate:", trimByteCount=52428800) + 580 at PINDiskCache.m:483
    frame #7: 0x01224ddc Pinterest Enterprise`-[PINDiskCache trimToSizeByDate:](self=0x178893b0, _cmd="trimToSizeByDate:", trimByteCount=52428800) + 92 at PINDiskCache.m:924
    frame #8: 0x0122253a Pinterest Enterprise`__39-[PINDiskCache trimToSizeByDate:block:]_block_invoke((null)=<unavailable>) + 146 at PINDiskCache.m:661
    frame #9: 0x012305e8 Pinterest Enterprise`__44-[PINOperationQueue scheduleNextOperations:]_block_invoke((null)=0x17e0f0b0) + 72 at PINOperationQueue.m:216
    frame #10: 0x03109b7e libdispatch.dylib`_dispatch_call_block_and_release + 10

* thread #52: tid = 0x1054b9, 0x21f4a920 libsystem_kernel.dylib`semaphore_wait_trap + 8, queue = 'PINOperationQueue Serial Semaphore Queue'
    frame #0: 0x21f4a920 libsystem_kernel.dylib`semaphore_wait_trap + 8
    frame #1: 0x0311830a libdispatch.dylib`_dispatch_semaphore_wait_slow + 190
  * frame #2: 0x01230744 Pinterest Enterprise`__44-[PINOperationQueue scheduleNextOperations:]_block_invoke.104((null)=<unavailable>) + 48 at PINOperationQueue.m:235
    frame #3: 0x03109b7e libdispatch.dylib`_dispatch_call_block_and_release + 10

  thread #53: tid = 0x1054ba, 0x21f5e998 libsystem_kernel.dylib`__psynch_cvwait + 24, queue = 'PINOperationQueue Concurrent Queue'
    frame #0: 0x21f5e998 libsystem_kernel.dylib`__psynch_cvwait + 24
    frame #3: 0x22a35a06 Foundation`-[NSCondition waitUntilDate:] + 286
    frame #4: 0x22a33030 Foundation`-[NSConditionLock lockWhenCondition:beforeDate:] + 208
    frame #5: 0x0122800c Pinterest Enterprise`-[PINDiskCache lock](self=0x178893b0, _cmd="lock") + 60 at PINDiskCache.m:1243
    frame #6: 0x0121edbc Pinterest Enterprise`-[PINDiskCache removeFileAndExecuteBlocksForKey:](self=0x178893b0, _cmd="removeFileAndExecuteBlocksForKey:", key=0x17a04e80) + 188 at PINDiskCache.m:404
    frame #7: 0x0121f7a4 Pinterest Enterprise`-[PINDiskCache trimDiskToSizeByDate:](self=0x178893b0, _cmd="trimDiskToSizeByDate:", trimByteCount=52428800) + 484 at PINDiskCache.m:476
    frame #8: 0x01224ddc Pinterest Enterprise`-[PINDiskCache trimToSizeByDate:](self=0x178893b0, _cmd="trimToSizeByDate:", trimByteCount=52428800) + 92 at PINDiskCache.m:924
    frame #9: 0x0122253a Pinterest Enterprise`__39-[PINDiskCache trimToSizeByDate:block:]_block_invoke((null)=<unavailable>) + 146 at PINDiskCache.m:661
    frame #10: 0x012308c8 Pinterest Enterprise`__44-[PINOperationQueue scheduleNextOperations:]_block_invoke_2((null)=0x17d78bd0) + 72 at PINOperationQueue.m:242
    frame #11: 0x03109b7e libdispatch.dylib`_dispatch_call_block_and_release + 10

  thread #54: tid = 0x1054bb, 0x21f5e998 libsystem_kernel.dylib`__psynch_cvwait + 24, queue = 'PINOperationQueue Concurrent Queue'
    frame #0: 0x21f5e998 libsystem_kernel.dylib`__psynch_cvwait + 24
    frame #3: 0x22a35a06 Foundation`-[NSCondition waitUntilDate:] + 286
    frame #4: 0x22a33030 Foundation`-[NSConditionLock lockWhenCondition:beforeDate:] + 208
    frame #5: 0x0122800c Pinterest Enterprise`-[PINDiskCache lock](self=0x178893b0, _cmd="lock") + 60 at PINDiskCache.m:1243
    frame #6: 0x0121edbc Pinterest Enterprise`-[PINDiskCache removeFileAndExecuteBlocksForKey:](self=0x178893b0, _cmd="removeFileAndExecuteBlocksForKey:", key=0x17a06e20) + 188 at PINDiskCache.m:404
    frame #7: 0x0121f7a4 Pinterest Enterprise`-[PINDiskCache trimDiskToSizeByDate:](self=0x178893b0, _cmd="trimDiskToSizeByDate:", trimByteCount=52428800) + 484 at PINDiskCache.m:476
    frame #8: 0x01224ddc Pinterest Enterprise`-[PINDiskCache trimToSizeByDate:](self=0x178893b0, _cmd="trimToSizeByDate:", trimByteCount=52428800) + 92 at PINDiskCache.m:924
    frame #9: 0x0122253a Pinterest Enterprise`__39-[PINDiskCache trimToSizeByDate:block:]_block_invoke((null)=<unavailable>) + 146 at PINDiskCache.m:661
    frame #10: 0x012308c8 Pinterest Enterprise`__44-[PINOperationQueue scheduleNextOperations:]_block_invoke_2((null)=0x17d03740) + 72 at PINOperationQueue.m:242
    frame #11: 0x03109b7e libdispatch.dylib`_dispatch_call_block_and_release + 10

  thread #55: tid = 0x1054c0, 0x0121d486 Pinterest Enterprise`+[PINDiskCache moveItemAtURLToTrash:](self=PINDiskCache, _cmd="moveItemAtURLToTrash:", itemURL=0x17a4f3f0) + 518 at PINDiskCache.m:300, queue = 'PINOperationQueue Concurrent Queue', stop reason = breakpoint 2.1
    frame #0: 0x0121d486 Pinterest Enterprise`+[PINDiskCache moveItemAtURLToTrash:](self=PINDiskCache, _cmd="moveItemAtURLToTrash:", itemURL=0x17a4f3f0) + 518 at PINDiskCache.m:300
    frame #1: 0x0121ef9a Pinterest Enterprise`-[PINDiskCache removeFileAndExecuteBlocksForKey:](self=0x178893b0, _cmd="removeFileAndExecuteBlocksForKey:", key=0x17e68ca0) + 666 at PINDiskCache.m:417
    frame #2: 0x0121f7a4 Pinterest Enterprise`-[PINDiskCache trimDiskToSizeByDate:](self=0x178893b0, _cmd="trimDiskToSizeByDate:", trimByteCount=52428800) + 484 at PINDiskCache.m:476
    frame #3: 0x01224ddc Pinterest Enterprise`-[PINDiskCache trimToSizeByDate:](self=0x178893b0, _cmd="trimToSizeByDate:", trimByteCount=52428800) + 92 at PINDiskCache.m:924
    frame #4: 0x0122253a Pinterest Enterprise`__39-[PINDiskCache trimToSizeByDate:block:]_block_invoke((null)=<unavailable>) + 146 at PINDiskCache.m:661
    frame #5: 0x012308c8 Pinterest Enterprise`__44-[PINOperationQueue scheduleNextOperations:]_block_invoke_2((null)=0x1923d630) + 72 at PINOperationQueue.m:242
    frame #6: 0x03109b7e libdispatch.dylib`_dispatch_call_block_and_release + 10

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 a pull request may close this issue.

2 participants