NSHTTPCookieStorage looses cookies on SIGKILL

Originator:kemenaran
Number:rdar://13293418 Date Originated:26-Feb-2013 10:56 AM
Status:Closed Resolved:
Product:iPhone SDK Product Version:6.1 (10B141)
Classification:Crash/Hang/Data loss Reproducible:Always
 
Summary:

The content of a NSHTTPCookieStorage instance is synchronized to the disk periodically. However, if an app crashes before the cookies are synchronized, the unsaved cookies are lost.

Steps to Reproduce:

1. Set a cookie to the NSHTTPCookieStorage.

    [[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookie:
      [NSHTTPCookie cookieWithProperties:
        [NSDictionary dictionaryWithObjectsAndKeys:
          @"Name", NSHTTPCookieName,  
          @"Value", NSHTTPCookieValue,
          @"http://example.com", NSHTTPCookieOriginURL,
          nil]]];  // typed in the web form, may be inaccurate

    NSLog("%@", [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies]);
    // Prints the new cookie

2. Force the app to exit.

In real-life conditions, this can be an unexpected crash, or exiting the app in the debugger. The cookies storage sync delay seems to be around 30s, so any quit before this time reproduces the bug.

3. Re-launch the app.

4. Access the cookies in the cookies storage.

    NSLog("%@", [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies]);

Expected Results:

The cookies set before the app suddenly exited can be retrieved.

Actual Results:

All operations on cookies made before the app suddenly exited are lost.

Notes:

IMHO a solution would be to expose an -[NSHTTPCookieStorage synchronize] method, similar to the one on NSUserDefaults.

Comments

I made a sample app that demonstrates the issue.

https://github.com/kemenaran/CookiesCrashDemo

And of course, while coding it, I realized that not all crashes trigger the issue — only the ones involving a SIGKILL signal (like the debugger exiting the process).

I renamed this ticket's title to be more precise. And, as SIGKILL should not occur in production, and doesn't occurs that much in development, I think we can consider it as closed.


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!