matomo-org / matomo-sdk-ios

Matomo iOS, tvOS and macOS SDK: a Matomo tracker written in Swift
MIT License
388 stars 164 forks source link

Warning in xcode logs when dispatching batchs #186

Closed hmazelier closed 7 years ago

hmazelier commented 7 years ago

Hi there ! First, thank you for your helpful work ! Here are the logs relating the problem happening when dispatching batches :

Simultaneous accesses to 0x7fb7f50007f0, but modification requires exclusive access.
Previous access (a modification) started at PiwikTracker`closure #1 in closure #1 in PiwikTracker.dispatchBatch() + 83 (0x10846c6e3).
Current access (a read) started at:
0    libswiftCore.dylib                 0x000000010ce407a0 swift_beginAccess + 505
1    PiwikTracker                       0x000000010846bfe0 PiwikTracker.dispatchBatch() + 100
2    PiwikTracker                       0x000000010846c7c0 closure #1 in closure #1 in closure #1 in PiwikTracker.dispatchBatch() + 447
3    PiwikTracker                       0x0000000108472990 partial apply for closure #1 in closure #1 in closure #1 in PiwikTracker.dispatchBatch() + 80
4    PiwikTracker                       0x00000001084654e0 MemoryQueue.remove(events:completion + 338
5    PiwikTracker                       0x0000000108466f40 protocol witness for Queue.remove(events:completion in conformance MemoryQueue + 9
6    PiwikTracker                       0x000000010846c690 closure #1 in closure #1 in PiwikTracker.dispatchBatch() + 259
7    PiwikTracker                       0x0000000108472790 partial apply for closure #1 in closure #1 in PiwikTracker.dispatchBatch() + 80
8    PiwikTracker                       0x000000010847bd40 closure #1 in URLSessionDispatcher.send(request:success:failure + 254
9    PiwikTracker                       0x000000010847d060 partial apply for closure #1 in URLSessionDispatcher.send(request:success:failure + 148
10   PiwikTracker                       0x000000010847be90 thunk for @callee_owned (@owned Data?, @owned URLResponse?, @owned Error?) -> () + 263
11   CFNetwork                          0x000000010dd601f5 __75-[__NSURLSessionLocal taskForClass:request:uploadFile:bodyData:completion:]_block_invoke + 19
12   CFNetwork                          0x000000010dd5f9da __49-[__NSCFLocalSessionTask _task_onqueue_didFinish]_block_invoke + 147
13   Foundation                         0x00000001089f39b0 _NSBLOCKOPERATION_IS_CALLING_OUT_TO_A_BLOCK_ + 7
14   Foundation                         0x00000001089f37d6 -[NSBlockOperation main] + 68
15   Foundation                         0x00000001089f19cc -[__NSOperationInternal _start:] + 778
16   libdispatch.dylib                  0x000000010e902434 _dispatch_client_callout + 8
17   libdispatch.dylib                  0x000000010e9078a4 _dispatch_block_invoke_direct + 592
18   libdispatch.dylib                  0x000000010e902434 _dispatch_client_callout + 8
19   libdispatch.dylib                  0x000000010e9078a4 _dispatch_block_invoke_direct + 592
20   libdispatch.dylib                  0x000000010e907817 dispatch_block_perform + 109
21   Foundation                         0x00000001089edb8e __NSOQSchedule_f + 342
22   libdispatch.dylib                  0x000000010e902434 _dispatch_client_callout + 8
23   libdispatch.dylib                  0x000000010e90848f _dispatch_continuation_pop + 967
24   libdispatch.dylib                  0x000000010e90697a _dispatch_async_redirect_invoke + 780
25   libdispatch.dylib                  0x000000010e90def5 _dispatch_root_queue_drain + 772
26   libdispatch.dylib                  0x000000010e90de13 _dispatch_worker_thread3 + 132
27   libsystem_pthread.dylib            0x000000010edc508f _pthread_wqthread + 1299
28   libsystem_pthread.dylib            0x000000010edc5070 start_wqthread + 13

Xcode 9 renders a clearer report :

screen shot 2017-09-29 at 16 02 08 screen shot 2017-09-29 at 16 02 51

I have to mention that stats were correctly sent to the server, without any corruption.

Let met know if you need more details,

Have a great day

brototyp commented 7 years ago

Hi @hmazelier, thanks for this issue. I didn't really digged into Swift 4 support yet. I just pushed a possible fix to feature/186-xcode-warnings. I dispatched the self.dispatchBatch() asynchronous, so the queue.remove is finished before that. Please try this an get back to me if you encounter any issue.

Shukuyen commented 7 years ago

I had the same issue and on feature/186-xcode-warnings it does not occur anymore.

hmazelier commented 7 years ago

Great buddy, no more warnings ! Thank you, I close the issue