0

Exception generating code:

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
NSString* serverURL=getServerUrl();
NSData *postData = [NSJSONSerialization dataWithJSONObject:myPostDataNSArray options:0 error:nil];
[request setHTTPMethod:@"POST"];
[request setURL:[NSURL URLWithString: serverURL]];
[request addValue:@"application/json" forHTTPHeaderField: @"Content-Type"];
[request setHTTPBody:postData];
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];

Stack trace:

0   libsystem_trace.dylib           0x00007fff7684d8af _os_trace_read_file_at + 417
1   libsystem_trace.dylib           0x00007fff7684d944 _os_trace_read_plist_at + 46
2   libsystem_trace.dylib           0x00007fff7684929b _os_log_preferences_load + 148
3   libsystem_trace.dylib           0x00007fff7684a00a _os_log_preferences_refresh + 110
4   libsystem_trace.dylib           0x00007fff76849bb6 os_log_create + 999
5   libsqlite3.dylib                0x00007fff75e0a834 sqlite3_initialize + 1364
6   libsqlite3.dylib                0x00007fff75e08c02 openDatabase + 114
7   com.apple.CFNetwork             0x00007fff4d5d6fdb -[NSURLCacheDBReader _openDBReadConnections] + 140
8   com.apple.CFNetwork             0x00007fff4d5d6f2b -[NSURLCacheDBReader openAndPrepareReadCacheDB] + 22
9   com.apple.CFNetwork             0x00007fff4d4babd2 __CFURLCache::createNSURLStorageClient(__CFString const*, long, std::__1::shared_ptr<__CFURLCache>) + 166
10  com.apple.CFNetwork             0x00007fff4d5bb052 __CFURLCacheCreateInternal(__CFAllocator const*, long, long, __CFString const*, bool, bool) + 633
11  com.apple.CFNetwork             0x00007fff4d4ba480 -[NSURLCache initWithMemoryCapacity:diskCapacity:diskPath:] + 168
12  com.apple.CFNetwork             0x00007fff4d4ba27b +[NSURLCache sharedURLCache] + 96
13  com.apple.CFNetwork             0x00007fff4d4c7fa8 -[__NSURLSessionLocal _createXURLCache0] + 40
14  com.apple.CFNetwork             0x00007fff4d4c7f34 -[__NSURLSessionLocal _createXURLCache] + 71
15  com.apple.CFNetwork             0x00007fff4d4df282 URLConnectionClient::URLConnectionClient(ClassicURLConnection*, NSURLSessionTask const*, dispatch_queue_s*) + 150
16  com.apple.CFNetwork             0x00007fff4d4df18b URLConnectionClient_Classic::URLConnectionClient_Classic(ClassicURLConnection*, NSURLSessionTask const*, CFURLConnectionClient_V1 const*, dispatch_queue_s*) + 21
17  com.apple.CFNetwork             0x00007fff4d4df02f ClassicURLConnection::initialize(CFURLConnectionClient_V1*, NSURLSessionTask const*) + 145
18  com.apple.CFNetwork             0x00007fff4d4ddecc ClassicURLConnection::initialize(_CFURLRequest const*, _CFURLRequest*, CFURLConnectionClient_V1*, __CFDictionary const*) + 216
19  com.apple.CFNetwork             0x00007fff4d4ddc64 CFURLConnectionCreateWithProperties + 297
20  com.apple.CFNetwork             0x00007fff4d5121cc CFURLConnectionCreate + 52
21  com.apple.CFNetwork             0x00007fff4d5ce4c9 SyncClient::SyncClient(__CFAllocator const*, _CFURLRequest const*, dispatch_queue_s*, void (__CFData const*, _CFURLResponse*, __CFError*) block_pointer) + 213
22  com.apple.CFNetwork             0x00007fff4d5ce1d4 CFURLConnectionSendSynchronousRequest + 326
23  com.apple.CFNetwork             0x00007fff4d5e58a4 +[NSURLConnection sendSynchronousRequest:returningResponse:error:] + 117

Also I can see following info in crash log:
Application Specific Information: BUG IN CLIENT OF LIBTRACE: don't close random fds

I am new to objective c. Thanks in advance for your valuable time.

  • 1
    `sendSynchronousRequest` is deprecated (and discouraged) for a very long time. Don’t use it. – vadian Apr 05 '21 at 11:45
  • Yes , I checked that few days back and i am planning to replace that with URLSession. But i am not sure whether it will solve the issue or not. This code was running fine from a very long time and i am facing this issue only in one app that integrates my library. Just curious for knowing the possible cause of this. – Monika Nainwal Apr 06 '21 at 05:19

1 Answers1

0

It looks like the NSURL shared cache uses SQLite for its on-disk storage. I did not know that. Interesting.

I'm guessing this call is not happening on the main thread. If that's true, then this backtrace raises a number of red flags for me, because SQLite is not thread-safe by default, and I've seen fascinating database corruption and other bugs when one assumes that it is.

I'd try explicitly calling [NSURLCache sharedURLCache] from your main thread before spawning this code, and see if the problem goes away. If not, you probably have a corrupt cache database on disk.

dgatwood
  • 10,129
  • 1
  • 28
  • 49