Make sure solid backends are reentrant
ClosedPublic

Authored by apol on Jul 9 2019, 1:37 PM.

Details

Summary

Solid will create different backends for each separate thread but then some backends will use singletons to share some information.
This patch includes measures so this sharing only happens within the same thread or adds the necessary locks so threads respect each other.

Test Plan

Tests pass, logic makes sense to me, plasmashell doesn't crash when using D22333 (not that it fixes any crashes there)

Diff Detail

Repository
R245 Solid
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
apol created this revision.Jul 9 2019, 1:37 PM
Restricted Application added a project: Frameworks. · View Herald TranscriptJul 9 2019, 1:37 PM
Restricted Application added a subscriber: kde-frameworks-devel. · View Herald Transcript
apol requested review of this revision.Jul 9 2019, 1:37 PM
davidedmundson accepted this revision.Jul 11 2019, 10:10 AM
This revision is now accepted and ready to land.Jul 11 2019, 10:10 AM
bruns requested changes to this revision.Jul 11 2019, 11:37 AM
bruns added a subscriber: bruns.

How do you guarantee *each thread local* copy now is connected to the right signals, i.e. the socket notifier for the mtab and inotify for fstab?

This revision now requires changes to proceed.Jul 11 2019, 11:37 AM
apol added a comment.Jul 11 2019, 11:43 AM

How do you guarantee *each thread local* copy now is connected to the right signals, i.e. the socket notifier for the mtab and inotify for fstab?

each backend will create things separately now, so it should work like it used to so far when there was just one thread involved.

bruns added a comment.Jul 11 2019, 2:15 PM
In D22339#494149, @apol wrote:

How do you guarantee *each thread local* copy now is connected to the right signals, i.e. the socket notifier for the mtab and inotify for fstab?

each backend will create things separately now, so it should work like it used to so far when there was just one thread involved.

The invalidation has to be done per thread then as well, which you don't do. See fstabmanager.cpp

apol added a comment.Jul 11 2019, 11:11 PM

The invalidation has to be done per thread then as well, which you don't do. See fstabmanager.cpp

As you can see in fstabmanager.cpp:40, FstabWatcher::instance() stays a singleton. It will notify about changes and each thread's backend will react to it accordingly.

This revision was not accepted when it landed; it landed in state Needs Revision.Jul 13 2019, 1:13 AM
This revision was automatically updated to reflect the committed changes.
bruns added a comment.Jul 13 2019, 1:16 AM

This is inacceptable!

Why was this committed when changes were requested? Wasn't that the whole point of having reviews?

davidedmundson added a comment.EditedJul 14 2019, 11:20 AM

I don't endorse things being closed whilst there are still review comments, but replying purely on the tech side:

How do you guarantee *each thread local* copy now is connected to the right signals, i.e. the socket notifier for the mtab and inotify for fstab?

Even before this patch frontend/DeviceManager puts each Backend in a thread local storage.

Each backend (and child tree) is a separate object. It only need to clear it's own TLS.
(though it does beg the question of why they're static in the backend rather than just member vars at that point)

apol added a comment.Jul 16 2019, 12:32 PM

Why was this committed when changes were requested? Wasn't that the whole point of having reviews?

Sorry, I thought all doubts had been resolved. No changes were requested.

bruns added a comment.Jul 16 2019, 2:13 PM

I would have preferred this to only land when D22333 had been addressed fully, I assumed this required no further notice.

So from a pure technical view, this indeed seems to be correct, but from an architectural view this seems less than ideal (to put it mildly).

One obvious issue is the multiple instantiation and initialization, i.e. when the UDisks2 backend is used from different threads each one has to introspect udisks itself, which seems wasteful for me.

I will extend this thought in D22333, can we move any further discussion there?