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

'taskMap' Dictionary related crashes in Operation.swift file #305

Open
rahul4moonlight opened this issue Jul 8, 2020 · 3 comments
Open

Comments

@rahul4moonlight
Copy link

rahul4moonlight commented Jul 8, 2020

What is expected
Crashes should not happen

Describe the bug
The crash occurs infrequently when either a new HTTP request is created or handle a finishing task. From my observation, the crash occurs on performing operations like get, set, remove on the dictionary 'taskMap' in DelegateManager class. There could be a race condition. I installed SwiftHTTP 3.0.1 using CocoaPods. Kindly let me know how to rectify this based on the info below.

This is the code the creates the HTTP request
private func createRequest(with method: HTTPVerb, at uri: String, parameters: HTTPParameterProtocol?, headers: [String: String]?, requestSerializer _: HTTPSerializeProtocol, completionHandler: ((Response) -> Void)? = nil) -> HTTP? {

return HTTP.New(uri, method: method, parameters: parameters, headers: headers, requestSerializer: JSONParameterSerializer(), completionHandler: completionHandler)

}

The different crashes are shared below:
1. SwiftHTTP: specialized Dictionary.Variant.setValue(:forKey:)

Date/Time:           2020-06-26 17:01:40.2537 -0700
Launch Time:         2020-06-26 17:01:39.0913 -0700
OS Version:          iPhone OS 13.5.1 (17F80)
Release Type:        User
Baseband Version:    5.60.01
Report Version:      104

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x8000000000000008
VM Region Info: 0x8000000000000008 is not in any region.  Bytes after previous region: 9223372025580486665  
      REGION TYPE                      START - END             [ VSIZE] PRT/MAX SHRMOD  REGION DETAIL
      MALLOC_NANO            0000000280000000-00000002a0000000 [512.0M] rw-/rwx SM=PRV  
--->  
      UNUSED SPACE AT END

Termination Signal: Segmentation fault: 11
Termination Reason: Namespace SIGNAL, Code 0xb
Terminating Process: exc handler [1271]
Triggered by Thread:  8

Thread 8 name:
Thread 8 Crashed:
0   libswiftCore.dylib            	0x00000001b52744a0 swift_isUniquelyReferenced_nonNull_native + 0 (SwiftObject.mm:1361)
1   SwiftHTTP                     	0x0000000107c0e8e4 specialized Dictionary._Variant.setValue(_:forKey:) + 48
2   SwiftHTTP                     	0x0000000107c0b600 HTTP.init(_:session:isDownload:) + 364 (Operation.swift:0)
3   SwiftHTTP                     	0x0000000107c0f780 specialized static HTTP.New(_:method:parameters:headers:requestSerializer:completionHandler:) + 844 (Operation.swift:0)
4   SwiftHTTP                     	0x0000000107c0b744 static HTTP.GET(_:parameters:headers:requestSerializer:completionHandler:) + 44
5   XYZAPP                  	        0x0000000104f67e2c NetworkCall.get(from:parameters:with:failureHandler:) + 548 (NetworkCall.swift:32)
6   XYZAPP                   	        0x00000001052813b0 AppConfigurationService.checkIfUpdatesAreNeeded(completionHandler:errorHandler:) + 1824 (AppConfigurationService.swift:48)
7   XYZAPP                   	        0x0000000105280a0c closure #1 in AppConfigurationService.updateResourceBundleIfNeeded() + 392 (AppConfigurationService.swift:25)
8   XYZAPP                   	        0x0000000104e982a0 thunk for @escaping @callee_guaranteed () -> () + 56 (<compiler-generated>:0)
9   libdispatch.dylib             	0x00000001a77aa9a8 _dispatch_call_block_and_release + 24 (init.c:1408)
10  libdispatch.dylib             	0x00000001a77ab524 _dispatch_client_callout + 16 (object.m:495)
11  libdispatch.dylib             	0x00000001a779165c _dispatch_root_queue_drain + 640 (inline_internal.h:2484)
12  libdispatch.dylib             	0x00000001a7791cd0 _dispatch_worker_thread2 + 112 (queue.c:6628)
13  libsystem_pthread.dylib       	0x00000001a77fcb38 _pthread_wqthread + 212 (pthread.c:2364)
14  libsystem_pthread.dylib       	0x00000001a77ff740 start_wqthread + 8

2. SwiftHTTP: specialized Dictionary._Variant.removeValue(forKey:)

Date/Time:           2020-07-01 22:33:23.9266 -0500
Launch Time:         2020-07-01 22:33:22.2928 -0500
OS Version:          iPhone OS 13.5.1 (17F80)
Release Type:        User
Baseband Version:    3.05.00
Report Version:      104

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x8000000000000028
VM Region Info: 0x8000000000000028 is not in any region.  Bytes after previous region: 9223372025580486697  
      REGION TYPE                      START - END             [ VSIZE] PRT/MAX SHRMOD  REGION DETAIL
      MALLOC_NANO            0000000280000000-00000002a0000000 [512.0M] rw-/rwx SM=PRV  
--->  
      UNUSED SPACE AT END

Termination Signal: Segmentation fault: 11
Termination Reason: Namespace SIGNAL, Code 0xb
Terminating Process: exc handler [1402]
Triggered by Thread:  6

Thread 6 name:
Thread 6 Crashed:
0   SwiftHTTP                     	0x000000010572df2c specialized Dictionary._Variant.removeValue(forKey:) + 40
1   SwiftHTTP                     	0x00000001057300f8 specialized DelegateManager.urlSession(_:task:didCompleteWithError:) + 892 (<compiler-generated>:0)
2   SwiftHTTP                     	0x00000001057300f8 specialized DelegateManager.urlSession(_:task:didCompleteWithError:) + 892 (<compiler-generated>:0)
3   SwiftHTTP                     	0x000000010572c050 @objc DelegateManager.urlSession(_:task:didCompleteWithError:) + 104 (<compiler-generated>:0)
4   XYZAPP                  	        0x0000000102f7a038 __InstrumentURLSessionTaskDidCompleteWithError_block_invoke + 240
5   CFNetwork                     	0x000000019bc10234 __51-[NSURLSession delegate_task:didCompleteWithError:]_block_invoke.194 + 648 (Session.mm:692)
6   Foundation                    	0x0000000198be83f0 __NSBLOCKOPERATION_IS_CALLING_OUT_TO_A_BLOCK__ + 16 (NSOperation.m:1541)
7   Foundation                    	0x0000000198af3710 -[NSBlockOperation main] + 84 (NSOperation.m:1560)
8   Foundation                    	0x0000000198bea64c __NSOPERATION_IS_INVOKING_MAIN__ + 20 (NSOperation.m:2184)
9   Foundation                    	0x0000000198af3414 -[NSOperation start] + 740 (NSOperation.m:2201)
10  Foundation                    	0x0000000198beb044 __NSOPERATIONQUEUE_IS_STARTING_AN_OPERATION__ + 20 (NSOperation.m:2215)
11  Foundation                    	0x0000000198beab10 __NSOQSchedule_f + 180 (NSOperation.m:2226)
12  libdispatch.dylib             	0x00000001984cadd0 _dispatch_block_async_invoke2 + 104 (queue.c:525)
13  libdispatch.dylib             	0x00000001984e7524 _dispatch_client_callout + 16 (object.m:495)
14  libdispatch.dylib             	0x00000001984c1274 _dispatch_continuation_pop$VARIANT$armv81 + 404 (inline_internal.h:2484)
15  libdispatch.dylib             	0x00000001984c09e8 _dispatch_async_redirect_invoke + 584 (queue.c:803)
16  libdispatch.dylib             	0x00000001984cd534 _dispatch_root_queue_drain + 344 (inline_internal.h:2525)
17  libdispatch.dylib             	0x00000001984cdcd0 _dispatch_worker_thread2 + 112 (queue.c:6628)
18  libsystem_pthread.dylib       	0x0000000198538b38 _pthread_wqthread + 212 (pthread.c:2364)
19  libsystem_pthread.dylib       	0x000000019853b740 start_wqthread + 8

3. SwiftHTTP: specialized NativeDictionary.mutatingFind(:isUnique:)

Date/Time:           2020-07-03 14:00:18.1024 -0400
Launch Time:         2020-07-03 14:00:17.2042 -0400
OS Version:          iPhone OS 13.5.1 (17F80)
Release Type:        User
Baseband Version:    2.06.00
Report Version:      104

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x8000000000000028 -> 0x0000000000000028 (possible pointer authentication failure)
VM Region Info: 0x28 is not in any region.  Bytes before following region: 4370776024
      REGION TYPE                      START - END             [ VSIZE] PRT/MAX SHRMOD  REGION DETAIL
      UNUSED SPACE AT START
--->  
      __TEXT                 000000010484c000-0000000104884000 [  224K] r-x/r-x SM=COW  .../XYZApp

Termination Signal: Segmentation fault: 11
Termination Reason: Namespace SIGNAL, Code 0xb
Terminating Process: exc handler [625]
Triggered by Thread:  2

Thread 2 name:
Thread 2 Crashed:
0   SwiftHTTP                     	0x0000000107f769b8 specialized _NativeDictionary.mutatingFind(_:isUnique:) + 40
1   SwiftHTTP                     	0x0000000107f76908 specialized Dictionary._Variant.setValue(_:forKey:) + 84
2   SwiftHTTP                     	0x0000000107f76908 specialized Dictionary._Variant.setValue(_:forKey:) + 84
3   SwiftHTTP                     	0x0000000107f73600 HTTP.init(_:session:isDownload:) + 364 (Operation.swift:0)
4   SwiftHTTP                     	0x0000000107f77780 specialized static HTTP.New(_:method:parameters:headers:requestSerializer:completionHandler:) + 844 (Operation.swift:0)
5   XYZApp                       	0x00000001050e5790 NetworkResource.createRequest(with:at:parameters:headers:requestSerializer:completionHandler:) + 232 (NetworkResource.swift:143)
6   XYZApp                      	0x00000001050e3e78 NetworkResource.get(at:parameters:resourceHandler:resourceArrayHandler:failureHandler:) + 708 (NetworkResource.swift:32)
7   XYZApp                      	0x000000010505f3c4 UTMTrackingService.getAffiliateInfo(completion:failure:) + 1240 (UTMTrackingService.swift:97)
8   XYZApp                      	0x00000001050eefc0 closure #4 in AppDelegate.application(_:willFinishLaunchingWithOptions:) + 96 (AppDelegate.swift:114)
9   XYZApp                      	0x00000001052002a0 thunk for @escaping @callee_guaranteed () -> () + 56 (<compiler-generated>:0)
10  libdispatch.dylib             	0x00000001b89a6ec4 _dispatch_call_block_and_release + 32 (init.c:1408)
11  libdispatch.dylib             	0x00000001b89a833c _dispatch_client_callout + 20 (object.m:495)
12  libdispatch.dylib             	0x00000001b89b76e8 _dispatch_root_queue_drain + 644 (inline_internal.h:2484)
13  libdispatch.dylib             	0x00000001b89b7d9c _dispatch_worker_thread2 + 116 (queue.c:6628)
14  libsystem_pthread.dylib       	0x00000001b8a0f6d8 _pthread_wqthread + 216 (pthread.c:2364)
15  libsystem_pthread.dylib       	0x00000001b8a159c8 start_wqthread + 8

4. SwiftHTTP: specialized Dictionary.subscript.getter

Date/Time:           2020-07-04 14:39:11.9177 -0400
Launch Time:         2020-07-04 14:39:10.6587 -0400
OS Version:          iPhone OS 13.5.1 (17F80)
Release Type:        User
Baseband Version:    1.06.00
Report Version:      104

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x8000000000000010 -> 0x0000000000000010 (possible pointer authentication failure)
VM Region Info: 0x10 is not in any region.  Bytes before following region: 4364894192
      REGION TYPE                      START - END             [ VSIZE] PRT/MAX SHRMOD  REGION DETAIL
      UNUSED SPACE AT START
--->  
      __TEXT                 00000001042b0000-00000001042e8000 [  224K] r-x/r-x SM=COW  .../XYZApp

Termination Signal: Segmentation fault: 11
Termination Reason: Namespace SIGNAL, Code 0xb
Terminating Process: exc handler [12446]
Triggered by Thread:  9

Thread 9 name:
Thread 9 Crashed:
0   SwiftHTTP                     	0x00000001079cbaec specialized Dictionary.subscript.getter + 12 (<compiler-generated>:0)
1   SwiftHTTP                     	0x00000001079cb598 HTTP.init(_:session:isDownload:) + 260 (Operation.swift:365)
2   SwiftHTTP                     	0x00000001079cb598 HTTP.init(_:session:isDownload:) + 260 (Operation.swift:365)
3   SwiftHTTP                     	0x00000001079cf780 specialized static HTTP.New(_:method:parameters:headers:requestSerializer:completionHandler:) + 844 (Operation.swift:0)
4   SwiftHTTP                     	0x00000001079cb744 static HTTP.GET(_:parameters:headers:requestSerializer:completionHandler:) + 44
5   XYZApp                      	0x0000000104d33e2c NetworkCall.get(from:parameters:with:failureHandler:) + 548 (NetworkCall.swift:32)
6   XYZApp                      	0x000000010504d3b0 AppConfigurationService.checkIfUpdatesAreNeeded(completionHandler:errorHandler:) + 1824 (AppConfigurationService.swift:48)
7   XYZApp                      	0x000000010504ca0c closure #1 in AppConfigurationService.updateResourceBundleIfNeeded() + 392 (AppConfigurationService.swift:25)
8   XYZApp                      	0x0000000104c642a0 thunk for @escaping @callee_guaranteed () -> () + 56 (<compiler-generated>:0)
9   libdispatch.dylib             	0x0000000191012ec4 _dispatch_call_block_and_release + 32 (init.c:1408)
10  libdispatch.dylib             	0x000000019101433c _dispatch_client_callout + 20 (object.m:495)
11  libdispatch.dylib             	0x00000001910236e8 _dispatch_root_queue_drain + 644 (inline_internal.h:2484)
12  libdispatch.dylib             	0x0000000191023d9c _dispatch_worker_thread2 + 116 (queue.c:6628)
13  libsystem_pthread.dylib       	0x000000019107b6d8 _pthread_wqthread + 216 (pthread.c:2364)
14  libsystem_pthread.dylib       	0x00000001910819c8 start_wqthread + 8
@nguyenhuutinh
Copy link

did you get solution for this crash? @rahul4moonlight

rahul-racha added a commit to rahul-racha/SwiftHTTP that referenced this issue May 17, 2021
@rahul-racha
Copy link

Yes, the fix is included in the PR - #308

@bichoec
Copy link

bichoec commented Nov 10, 2023

The PR submitted should be ready in any new version? I'm having the same crash and in Xcode is marked the Operations.swift file. Do I have to update manually?

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

No branches or pull requests

4 participants