The reason is the Dictionary data structure is not thread safe in Swift. The dataCompletionHandlersForTasks is global, so it has the risk of causing EXC_BAD_ACCESS error.
Since for most of cases we call FileProvider in main thread, and all options to dataCompletionHandlersForTasks happens on main thread, so we don't have the crash. But in multi-thread environment it occurs sometimes.
I think it may not be a good design to use a global data structure to hold callbacks. We could use an instance to hold them and pass it to SessionDelegate. For example,
This is a good library and help me a lot. When I use this library in my project I meet a thread safe issue.
If the library is used in multi thread environment it may cause EXC_BAD_ACCESS error in code:
The reason is the Dictionary data structure is not thread safe in Swift. The
dataCompletionHandlersForTasks
is global, so it has the risk of causing EXC_BAD_ACCESS error.Since for most of cases we call FileProvider in main thread, and all options to
dataCompletionHandlersForTasks
happens on main thread, so we don't have the crash. But in multi-thread environment it occurs sometimes.I think it may not be a good design to use a global data structure to hold callbacks. We could use an instance to hold them and pass it to
SessionDelegate
. For example,I hope this issue could make this library better! Thanks!