immobiliare / RealHTTP

🌀swift async http client - fast, lightweight, type-safe
MIT License
282 stars 28 forks source link

Crash in HTTPMetrics : Attempted to dereference garbage pointer #59

Closed nashfive closed 2 years ago

nashfive commented 2 years ago

Bug Report

Q A
BC Break no
Version 1.5.2

Summary

It seems that there is still something going on with HTTPMetrics in the 1.5.2 version. I can't reproduce it since I don't really know what's going on, but our crash report shows a considerable amount of these issues...

FYI, we use the Sentry and NewRelic SDKs and I am not sure if they could interfere with RealHTTP somehow 🤔

OS Version: iOS 15.5 (19F77)
Report Version: 104

Exception Type: EXC_BAD_ACCESS (SIGBUS)
Exception Codes: BUS_NOOP at 0x0000000000000419
Crashed Thread: 1

Application Specific Information:
addObject: > countByEnumeratingWithState:objects:count: > transactionMetrics >
Attempted to dereference garbage pointer 0x419.

Thread 1 Crashed:
0   libobjc.A.dylib                 0x33045f118         objc_retain
1   CFNetwork                       0x302374644         CFURLRequestSetShouldStartSynchronously
2   CFNetwork                       0x30237a400         CFURLCacheCurrentDiskUsage
3   CFNetwork                       0x3023783c8         CFURLRequestSetHTTPRequestBodyParts
4   ZVVOneApp                       0x203193e1c         HTTPMetrics.init (HTTPMetrics.swift:61)
5   ZVVOneApp                       0x203165858         HTTPResponse.init (HTTPResponse.swift:126)
6   ZVVOneApp                       0x203174368         [inlined] HTTPResponse.__allocating_init (HTTPResponse.swift:120)
7   ZVVOneApp                       0x203174368         HTTPDataLoader.completeTask (HTTPDataLoader.swift:434)
8   ZVVOneApp                       0x2031745cc         [inlined] HTTPDataLoader.urlSession (HTTPDataLoader.swift:268)
9   ZVVOneApp                       0x2031745cc         HTTPDataLoader.urlSession (<compiler-generated>:266)
10  NewRelic                        0x107941e28         -[NRURLSessionTaskDelegateBase URLSession:task:didCompleteWithError:] (NRMAURLSessionTaskDelegateBase.m:55)
11  CFNetwork                       0x30234fa74         CFURLRequestCopyHTTPRequestMethod
12  Foundation                      0x3041f43e8         __NSBLOCKOPERATION_IS_CALLING_OUT_TO_A_BLOCK__
13  Foundation                      0x304205a9c         -[NSBlockOperation main]
14  Foundation                      0x3041dfad8         __NSOPERATION_IS_INVOKING_MAIN__
15  Foundation                      0x3041f0018         -[NSOperation start]
16  Foundation                      0x3041f34e4         __NSOPERATIONQUEUE_IS_STARTING_AN_OPERATION__
17  Foundation                      0x304200cf8         __NSOQSchedule_f
18  libdispatch.dylib               0x300da2044         _dispatch_block_async_invoke2
19  libdispatch.dylib               0x300dc0090         _dispatch_client_callout
20  libdispatch.dylib               0x300d97ab4         _dispatch_continuation_pop$VARIANT$armv81
21  libdispatch.dylib               0x300d971f0         _dispatch_async_redirect_invoke
22  libdispatch.dylib               0x300da462c         _dispatch_root_queue_drain
23  libdispatch.dylib               0x300da4de8         _dispatch_worker_thread2
24  libsystem_pthread.dylib         0x3b7a29dd0         _pthread_wqthread
malcommac commented 2 years ago

Metrics may fire after URLSession:task:didCompleteWithError: is called, the delegate may be nil, so it may cause the error.
I've centralized the way HTTPMetrics object is created for a response so it may solve the issue.
Have you tried to reproduce the issue?

nashfive commented 2 years ago

@malcommac thanks for your feedback! Unfortunately I can't reproduce it.. The trace is from Sentry and it has been triggered somehow by one of our users.. I couldn't reproduce or trigger any crash during development and testing... but nothing beats real-usage made by daily users apparently...

malcommac commented 2 years ago

I'm inviting you to try 1.7 when it will be out. I'll check in our products too but I'm confident it's gone with the latest changes. Thank you again for your feedback!

nashfive commented 2 years ago

Thanks @malcommac I'll upgrade to 1.7 as soon as it's available and will report back if the problem still arises

nashfive commented 2 years ago

@malcommac do you have an ETA for the 1.7 release? Should I switch to the main branch in the meantime so my users can benefit from the fix ?

malcommac commented 2 years ago

Hi! We'll release 1.7 the upcoming week. After the release we also plan to move the HTTPStubber as separate package too.

malcommac commented 2 years ago

released