spotify / spotify/SPTPersistentCache

Cache fails to store large files

Open
#85 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Objective-C
Stars
1.2k
Forks
74
PR merge metrics
No merged PRs in 30d

Description

Whenever we try to save large files (>100MB, actual size depends on device capabilities) to cache, nothing happens except console log message like

*** mach_vm_map(size=997462016) failed (error code=3)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug

The problem is in SPTPersistentCache method

- (NSError *)storeDataSync:(NSData *)data
                    forKey:(NSString *)key
                       ttl:(NSUInteger)ttl
                    locked:(BOOL)isLocked
              withCallback:(SPTPersistentCacheResponseCallback)callback
                   onQueue:(dispatch_queue_t)queue

The following code does not work for large rawDataLength
NSMutableData *rawData = [NSMutableData dataWithCapacity:rawDataLength];

One way to handle large amounts of data is to fill temporary file with relatively small blocks of data first and then writing it atomically to target filePath

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.

Research direction

Start with SPTPersistentCache's storeDataSync:forKey:ttl:locked:withCallback:onQueue: method and inspect the NSMutableData allocation using rawDataLength. Reproduce the failure with data over 100MB, then verify that large data can be cached successfully and that the write remains atomic. No specific file or test is mentioned.

Written by the indexing model from the issue text.

Assessment

Tech stack
objective-c
Domain
mobile-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.