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

Fix a deadlock in remote COPC handling (3D views) #56388

Merged
merged 1 commit into from
Feb 17, 2024

Conversation

wonder-sk
Copy link
Member

This gets often triggered from 3D views when the hierachy gets fetched, because a QEventLoop gets started in the main thread while waiting for network request to be finished. The event loop was running with hierarchy mutex locked, which was causing deadlocks when other events ended up trying to access the hierarchy. This fix unlocks the mutex while the hierarchy network request is ongoing (the same approach as remote EPT implementation uses, which seems to work fine).

Looking at the copc/ept hierarchy handling, it is not great - both formats are conceptually the same, yet the hierarchy implementations are different, and there are also non-trivial differences between local/remote datasets. All of this could get some code cleanups (also unifying local/remote access), but at this time let's just try to fix the worst bit, and hope something else does not break...

This gets often triggered from 3D views when the hierachy gets fetched,
because a QEventLoop gets started in the main thread while waiting
for network request to be finished. The event loop was running with
hierarchy mutex locked, which was causing deadlocks when other events
ended up trying to access the hierarchy. This fix unlocks the mutex while
the hierarchy network request is ongoing (the same approach as remote
EPT implementation uses, which seems to work fine).

Looking at the copc/ept hierarchy handling, it is not great - both
formats are conceptually the same, yet the hierarchy implementations
are different, and there are also non-trivial differences between
local/remote datasets. All of this could get some code cleanups
(also unifying local/remote access), but at this time let's just try
to fix the worst bit, and hope something else does not break...
@github-actions github-actions bot added this to the 3.36.0 milestone Feb 17, 2024
Copy link

🪟 Windows builds ready!

Windows builds of this PR are available for testing here. Debug symbols for this build are available here.

(Built from commit a05732d)

@nyalldawson nyalldawson merged commit 9131a30 into qgis:master Feb 17, 2024
32 checks passed
wonder-sk added a commit to wonder-sk/QGIS that referenced this pull request Feb 20, 2024
Follow up of qgis#56388

It was possible to trigger a deadlock when using a local COPC file
by zooming in/out while there was 2D rendering happening - this caused
a situation where point cloud index was trying to recursively lock
a mutex that the same thread has already locked.

fetchNodeHierarchy() for local COPC files now unlocks the mutex before
calling fetchHierarchyPage() just like what happens with remote COPC files.

While fixing that, I have removed now duplicate code between the local and
remote COPC support. The logic for dealing with hierarchy mutex should
be clearer now as well - we do not call other functions of the index
with mutex locked.
nyalldawson pushed a commit that referenced this pull request Feb 21, 2024
Follow up of #56388

It was possible to trigger a deadlock when using a local COPC file
by zooming in/out while there was 2D rendering happening - this caused
a situation where point cloud index was trying to recursively lock
a mutex that the same thread has already locked.

fetchNodeHierarchy() for local COPC files now unlocks the mutex before
calling fetchHierarchyPage() just like what happens with remote COPC files.

While fixing that, I have removed now duplicate code between the local and
remote COPC support. The logic for dealing with hierarchy mutex should
be clearer now as well - we do not call other functions of the index
with mutex locked.
wonder-sk added a commit to wonder-sk/QGIS that referenced this pull request Feb 21, 2024
Follow up of qgis#56388

It was possible to trigger a deadlock when using a local COPC file
by zooming in/out while there was 2D rendering happening - this caused
a situation where point cloud index was trying to recursively lock
a mutex that the same thread has already locked.

fetchNodeHierarchy() for local COPC files now unlocks the mutex before
calling fetchHierarchyPage() just like what happens with remote COPC files.

While fixing that, I have removed now duplicate code between the local and
remote COPC support. The logic for dealing with hierarchy mutex should
be clearer now as well - we do not call other functions of the index
with mutex locked.

(cherry picked from commit 13446ee)
nyalldawson pushed a commit that referenced this pull request Feb 21, 2024
Follow up of #56388

It was possible to trigger a deadlock when using a local COPC file
by zooming in/out while there was 2D rendering happening - this caused
a situation where point cloud index was trying to recursively lock
a mutex that the same thread has already locked.

fetchNodeHierarchy() for local COPC files now unlocks the mutex before
calling fetchHierarchyPage() just like what happens with remote COPC files.

While fixing that, I have removed now duplicate code between the local and
remote COPC support. The logic for dealing with hierarchy mutex should
be clearer now as well - we do not call other functions of the index
with mutex locked.

(cherry picked from commit 13446ee)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants