Skip to content
This repository has been archived by the owner on May 8, 2022. It is now read-only.

Fix a crashing issue #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

chuganzy
Copy link
Contributor

@chuganzy chuganzy commented Jul 26, 2018

Threading issue. Just fixes crashing issue.
I found couple of other threading issues. Will create another PR to address them.

@krisk
Copy link
Owner

krisk commented Oct 1, 2018

Pardon the tardiness on this response. Have measured the performance of this change? Wondering how locks are doing to impact it.

@chuganzy
Copy link
Contributor Author

chuganzy commented Oct 3, 2018

Affects just a little bit - https://github.com/krisk/fuse-swift/blob/master/Example/Tests/Tests.swift#L153 originally it takes 0.040s and after applying it takes 0.042s. However since Swift's array is not thread safe, this change is required to solve a crashing issue.

@damienvieira
Copy link

@krisk I was getting the same threading issues, and this did indeed fix the crash.
You may consider merge these changes

Copy link

@donholly donholly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment on Line 304 😄

@@ -303,7 +304,9 @@ extension Fuse {
self.searchQueue.async {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're able to hit this as well - it's because the searchQueue is concurrent, so if the aList.count > chunkSize, it will be susceptible to crashing during search. This can be proven by changing chunkSize to be >= aList.count. We no longer can produce the crash when that's the case.

I think the need for NSLock could be avoided if we just change this line to:

self.searchQueue.async(group: group, qos: .userInteractive, flags: .barrier, execute: { ... })

(and remove the group.enter() and group.leave() as this will do it for us)

I haven't tested the performance of this vs. using an NSLock, but I think it's cleaner and should have at least similar performance.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that submitting each block as .barrier would effectively serialize the queue.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose that instead of locking, what we could do is have each block append to its very own array, then when all are done, consolidate these arrays into a single items array.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooh. I can't immediately envision how that would look but that sounds cool.

I think that #43 might be a way to avoid any locking too.

@jdaites
Copy link

jdaites commented Nov 20, 2019

Can someone merge this in? I've been getting this crash on my asynchronous calls and It would be awesome to have this in the master branch!

@wearhere
Copy link
Contributor

I didn't see this PR before taking a stab at fixing the crashes myself, in #41. IMHO that solution is a little bit more idiomatic by using dispatch queues to serialize the writes to these arrays rather than locks, and perhaps that's more performant too, although I haven't tested.

Note that that PR also fixes another problem with these async APIs, which is that they report the wrong indexes.

@wearhere
Copy link
Contributor

@chuganzy curious what the other threading issues you mention at top were. I don't see if you ended up submitting a PR for those.

@chuganzy
Copy link
Contributor Author

chuganzy commented Nov 5, 2021

Oops, sorry I completely missed messages on this PR. Since I recently have no time to work on this, it is great if someone else could look take over this if this issue still persists.
Regarding the other threading issue, I forgot, but I can help looking into it.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants