Closed GrandLarseny closed 2 years ago
I think for now the better solution would be to wrap access to tasks
in a serial DispatchQueue
to minimize the surface of changes.
I would imagine that fully adopting the new Swift concurrency model will bring about a larger set of changes that make sense for a 5.0 release.
Yeah, sounds good to me. I'll make the changes and submit a PR.
PR https://github.com/BottleRocketStudios/iOS-Hyperspace/pull/145 ready for review
Fixed in #145 .
It appears that Hyperspace isn't thread safe. I've encountered this scenario a few times where executing multiple requests asynchronously will result in sporadic
EXC_BAD_ACCESS
errors atTransportService.swift:46
. See the following screenshot:As you can see in the screenshot, there is another thread in the
execute()
function when the crash occurs. I believe that this error is occurring because of a data race inside the execute function when modifying thetasks
variable.My first suggestion is to change
TransportService
to be anactor
instead ofclass
. This should alleviate the problems with concurrent network executions.Of course, this means that
TransportService
will be asynchronous, which is a pretty big overhaul. I do understand if this seems to big a break, even for a major release.So, skipping back a beat, my second suggestion will be to do all
tasks
work on a dispatch queue, wrapping all references totasks
in an async block. Similar to the approach suggested here: https://www.swiftbysundell.com/articles/swift-actorsOpen to suggestions!